2017-02-09 4 views
1

Google Documentationという公式を使用して住所検索を作成しています。Googleプレイスの結果が特定の地域に偏っている

Android版では、自分の地域に結果を偏らせることができます。

たとえば、「123 Main St」の入力は、他の結果を表示する前に私の町のMain stを最初に表示します。

iOSでは、これを行う方法を理解できません。私はGMSAutocompleteViewControllerデリゲートで "フルスクリーンコントロールを追加"を使用しています。

GMSCoordinateBoundsがありますが、マップの例です。私は地図を使用していません。

私はこのようなもので動き回っていますが、動作させることはできません。私は正しい軌道にいるのだろうか?

- (void) placeAutocomplete : (NSString*) location : Bounds:(GMSCoordinateBounds *)bounds{               
[_placesClient autocompleteQuery:location 
          bounds:bounds 
          filter:filter 
         callback:^(NSArray *results, NSError *error) { 
          if (error != nil) { 
          NSLog(@"Autocomplete error %@", [error localizedDescription]); 
          return; 
          } 

          for (GMSAutocompletePrediction* result in results) { 
          NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID); 
          } 
         }]; 
} 

任意のヘルプ?

答えて

2

次の例のように、直接GMSAutocompleteViewControllerに境界を設定することができます。

// Present the Autocomplete view controller when the button is pressed. 
@IBAction func autocompleteClicked(_ sender: UIButton) { 
    let autocompleteController = GMSAutocompleteViewController() 
    autocompleteController.delegate = self 

    // Set bounds to inner-west Sydney Australia. 
    let neBoundsCorner = CLLocationCoordinate2D(latitude: -33.843366, 
               longitude: 151.134002) 
    let swBoundsCorner = CLLocationCoordinate2D(latitude: -33.875725, 
               longitude: 151.200349) 
    let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner, 
            coordinate: swBoundsCorner) 

    autocompleteController.bounds = bounds 

    present(autocompleteController, animated: true, completion: nil) 
} 
+0

ありがとうございますが、どうやってバウンディングボックスの緯度/経度を計算していますか?あなたはあなたがいる場所の中心を見つめて20マイルを広げていますか? – JasonBourne

+0

私は上記のコード(Googleの開発サイトのcopypasta)についてはわかりませんが、latlngポイントの周りに20マイルのバウンディングボックスを計算する場合は、SphericalUtilのメソッドが役に立ちます(https://developers.google.com/マップ/ドキュメント/ android-api/utility /#球形) – AndrewR

0

あなたの場所に基づいて境界を作成し、GMSAutocompleteViewController

の境界として設定
func presentAddressFinder(){ 
    let autocompleteController = GMSAutocompleteViewController() 
     autocompleteController.delegate = self 
     let bounds = GMSCoordinateBounds() 
     autocompleteController.autocompleteBounds = bounds.includingCoordinate(currentLocation) 
    present(autocompleteController, animated: true, completion: nil) 
} 

ここにcurrentLocation現在のデバイスの場所ですCLLocationCoordinate2D!

関連する問題