Google Maps SDK integration in iOS apps has nowadays become pretty common due to its flexible features and small size. This tutorial will walk you through the whole process in step by step manner about how to integrate the Google Map.
Get the SDK for Google Maps from Google Developers Site.
You can obtain a key for your app in the Google APIs Console.
For using places API in your project, you will need a ‘browser key’ instead of an ‘iOS key’. To get the browser key follow the first two steps mentioned for obtaining the API key for Google Map Integration . After that follow the steps mentioned below:
The Google Maps SDK for iOS is packaged as a static framework with an included resource bundle. Before you can add a map to your application, you will need to add the framework to your project, and configure your build settings in Xcode. These instructions assume an installation for a new project. If you are working with an existing project, you may not have to follow the steps exactly as described.
[GMSServices provideAPIKey:@"API_KEY”];
After adding the key in your app delegate all you are left with is showing map in your view controller. For that in your ViewController.m and add following
#import<GoogleMaps/GoogleMaps.h>
Then add the following lines of codes in your ViewController.m under ViewDidLoad() method:
//Create a GMSCameraPosition that tells the map to display the //coordinate 22.595769, 88.263639 at zoom level 6. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:22.595769 longitude:88.263639 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; //Creates a marker at kolkata location. GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(22.595769, 88.263639); marker.title = @"Howrah"; marker.snippet = @"Kolkata"; marker.map = mapView_;
After that you can do whatever you wish with the Google Map with the help of Google Map Object reference.
If you wish to play with drawing objects like markers, tiles etc. refer to the link Google map markers reference. Google Places API provide search facility with respect to a service. Those services can be seen listed in Places API Supported types .
For having this facility in your app the only thing you have to do is to make an API call using the Browser key you obtained while configuring your project on Google API console. The sample API for nearby search is given below:
The obtained JSON can be parsed and you can show the search results on the map using the location of the objects obtained in the JSON. For more details on how to use the Places API, refer to the link Google Places Search Request.
For Google Maps integration sample Code and tracking location using maps, you can refer to this sample project on GitHub.
For tracking location using device GPS, you can refer to this sample project on GitHub.
This is it. Hope it helps. Feel free to comment if you face any problem while integrating Google Maps SDK. Any suggestion for improvement will be appreciated.