September 30, 2015 at 10:36 pm #1818
This is the official thread to discuss the following tutorial post: How to use the Google Places Autocomplete API with Google Maps SDK on iOSOctober 28, 2015 at 1:30 am #2006
Great tutorial, thank you!
I am hoping to localize the autocomplete around the users location.
Any idea on how to accomplish this given the project posted?October 28, 2015 at 10:48 pm #2008
Hi Corey, one way to do this is by using the place picker API which will return places and POI around the user location. I wrote a completed tutorial about that here.
However, if you don’t want to use the place picker API, you can filter the autocomplete entries returned from the API and compare their corresponding lon/lat to the user location coordinates, and hence only display the places with coordinates around the user (Although this will be a heavy processing task). The right method to such processing is in the
searchBar:textDidChange:protocol method (before the
self.searchResultController.reloadDataWithArray(self.resultsArray)statement).March 7, 2016 at 2:25 pm #2862
First: great tutorial! I got everything working fine in my app by following it!
Only, there is one thing i can’t seem to fix. When i search for a specific address (a street + number) everything works fine. But when i search for a specific place, for instance a bar or restaurant, it doesn’t return the exact address (it looks like it only returns the street is on and not the number, so my marker is usually a few 100m off). I think it has something to do with geocode vs places api.
Is there some way to fix this so that the search will also return an exact address (with the street number) when you search for a place?
Tnx in advance! JorisMarch 7, 2016 at 4:50 pm #2866
The Google places autocomplete API will return suggestions based on the text you type in. Although this is rare, it happens that such place address can not be provided accurately by the services. Can you let me know what exactly is the specific place you are trying to look for, so that I can try and debug it on my own. Then I will confirm 🙂March 8, 2016 at 7:52 am #2869
It happens when i search for a bar or restaurant in my hometown (Amsterdam, Netherlands). For instance the Golden Brown Bar, which is located on Jan Pieter Heijestraat 146, Amsterdam, if i search for it online with google maps in my browser.
The implemented search result controller does give back the name of the bar and the street name, but not the exact street number, so eventually in the app the marker gets dropped a few hundred meters off, somewhere else in the street (looks like somewhere in the middle, around number 110).
I’ve been doing some testing and reading online myself, and think it has something to do with using the google maps geocode api and not the GM places api in UITableViewDelegate Protocol.
let url = NSURL(string: “https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)&sensor=false”)
When I print the results of the api request to the console it confirms that there is no exact street number returned.
For instance, see also this link (not specifically for iOS but handles the same problem).
Can you work with this for debugging?
Cheers! JorisMarch 9, 2016 at 9:10 pm #2872
I just debugged the Golden Brown Bar address. The Google Places API is returning the following suggestion:
The Golden Brown Bar, Jan Pieter Heijestraat, Amsterdam, Netherlands
This is before using the geocoding API for sure. It’s weird because when trying it on the google maps for web, it’s returning the address with the street number. So most likely that google places API for mobile is not working the same way google maps for web is dealing with addresses.