Home Forums iOS Development How to use the Google Places Autocomplete API with Google Maps SDK on iOS

This topic contains 6 replies, has 2 voices, and was last updated by  Malek 1 year ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1818 Reply

    Malek
    Keymaster

    This is the official thread to discuss the following tutorial post: How to use the Google Places Autocomplete API with Google Maps SDK on iOS

    #2006 Reply

    Corey

    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?

    #2008 Reply

    Malek
    Keymaster

    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).

    #2862 Reply

    Joris

    Hi Malek,

    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! Joris

    #2866 Reply

    Malek
    Keymaster

    Hi Joris,
    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 🙂

    #2869 Reply

    Joris

    Hi Malek,

    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).
    http://stackoverflow.com/questions/32105747/google-maps-geocoding-api-returning-different-address-than-google-maps

    Can you work with this for debugging?

    Cheers! Joris

    #2872 Reply

    Malek
    Keymaster

    Hi Joris,
    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.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: How to use the Google Places Autocomplete API with Google Maps SDK on iOS
Your information: