Using Google Places API for iOS, I am using the Place AutoComplete feature. When I start typing a place name for example 'Starbucks' it gives me starbucks location in several countries but not my local starbucks. How do I pass the current location to the API so the search results start from closest to my location?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can pass a GMSCoordinateBounds
to the which is "object biasing the results to a specific area specified by latitude and longitude bounds".
They have an example on their site showing how to do this:
let visibleRegion = self.mapView.projection.visibleRegion()
let bounds = GMSCoordinateBounds(coordinate: visibleRegion.farLeft, coordinate: visibleRegion.nearRight)
let filter = GMSAutocompleteFilter()
filter.type = GMSPlacesAutocompleteTypeFilter.City
placesClient.autocompleteQuery("Sydney Oper", bounds: bounds, filter: filter, callback: { (results, error: NSError?) -> Void in
guard error == nil else {
print("Autocomplete error \(error)")
return
}
for result in results! {
print("Result \(result.attributedFullText) with placeID \(result.placeID)")
}
})
This example show how to pull this data from a map view but you can also create the GMSCoordinateBounds
manually.
Hope this helps.