2017-09-04 17 views
0

Swift 3.0でGoogleプレイスを使用してGoogleオートコンプリートを実行しようとしています。しかし、私は現在の場所に応じて検索する必要があります。例:私はインドのカルカッタにいて、検索キーワード「コ」を入力すると、コルカタの結果が最初に表示されますローカル検索でスムーズGoogleオートコンプリート

誰でも助けてくれますか? ここに私のコードです。 は、私は私のクラスでGooglePlaces // MARK

@IBAction func txtFieldLocationDidStartEditing(_ sender: Any) { 
    self.placeAutocomplete() 
} 
func placeAutocomplete() { 
    let autocompleteController = GMSAutocompleteViewController() 
     autocompleteController.delegate = self 
    present(autocompleteController, animated: true, completion: nil) 
} 

をインポート: - オートコンプリート代表

func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) { 
    print("Place name: \(place.name)") 
    dismiss(animated: true, completion: nil) 
} 

func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) { 
    // TODO: handle the error. 
    print("Error: ", error.localizedDescription) 
} 

// User canceled the operation. 
func wasCancelled(_ viewController: GMSAutocompleteViewController) { 
    dismiss(animated: true, completion: nil) 
} 

// Turn the network activity indicator on and off again. 
func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) { 
    UIApplication.shared.isNetworkActivityIndicatorVisible = true 
} 

func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) { 
    UIApplication.shared.isNetworkActivityIndicatorVisible = false 
} 

誰も私はそれを解決するために助けてください。 ありがとうございます。

+0

あなたは正常に動作している境界を設定、あなたが@nathanありがとうあなたのMapViewのバウンディングボックス – nathan

答えて

1

GMSAutocompleteViewControllerが提供する唯一のAPIは、そう(reference)のようなGMSCoordinateBoundsを設定することです:

func placeAutocomplete() { 
    let visibleRegion = mapView.projection.visibleRegion() 
    let bounds = GMSCoordinateBounds(coordinate: visibleRegion.farLeft, coordinate: visibleRegion.nearRight) 

    let autocompleteController = GMSAutocompleteViewController() 
    acController.autocompleteBounds = bounds 
    autocompleteController.delegate = self 
    present(autocompleteController, animated: true, completion: nil) 
} 
+0

とAPIを供給することができます。 –

関連する問題