Reputation: 4632
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?
Upvotes: 1
Views: 660
Reputation: 763
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.
Upvotes: 3