Search code examples
iosobjective-cgoogle-maps-sdk-ios

Searching locations with name in google maps sdk in ios


I am using Google map sdk in my project. I have search bar at top and I have to search the location that user enter in that search bar. Secondly search bar should give hints like if we search location in Google maps application.Any help will be appreciate able.


Solution

  • Prerequisites

    1. Google Places API KEY

    Get Started with GOOGLE PLACE API on iOS

    STEPS

    1. You need to create an url using the text entered in your textfield.
    2. Append the text from textfield the create an url like this

      NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&key=%s",queryText,kGooglePlaceAPIKey]];

    where queryText is the text, and kGooglePlaceAPIKey is your GOOGLE PLACES API KEY.

    1. Do JSON Parsing on this URL.

    2. You will get the information of all location related to the text entered in your textfield.

    Figure : JSON Response on Firefox Browser using JSONViewer Addon

    JSON Response on Firefox Browser

    FOR MORE INFORMATION REFER THIS SITE : Google Places Text Search Requests

    Hope it helps You Cheers :)