Today I’m going to show you guys how easily one can integrate Google Maps to their apps.
Prerequisites:
- Xcode 6.3 or above
- CocoaPods Installed
Create an empty project, then open your terminal and type the following lines:
Just type cd and drag your project to the terminal it will automatically detect your path to the project.
Now type:
Then type the following lines it will open your Podfile:
Copy the following lines in your Podfile after target:
Your Podfile will look something like this:
Save it and close it then come back to your terminal and type:
It will start installing the SDK.
And you’ll see outputs like:
Now go back to your project and you’ll see a file named yourproject.xcworkspace, similar to this:
Open its xcworkspace file, add a bridging header to your project and import GoogleMaps:
[code language=”css”]#import <GoogleMaps/GoogleMaps.h>[/code]
Then open your AppDelegate.swift and add your iOS API Key that you obtained from Google Developers’console:
[code language=”css”] GMSServices.provideAPIKey(“Your-iOS-API-Key”)[/code]
Now open your Main.storyboard and drag a UIView:
and apply constraints to it:
Click on your View and add GMSMapView as its Custom Class:
Now create a layout of the View of type GMSMapView:
Its time to the set the camera of the map. Lets say we want it to appear over Sydney, Australia when our app starts, then in your viewDidLoad do:
Now set up the marker; for that we are going to use GoogleMaps’ GMSMarker class. In your viewDidLoad write:
Save and Run it, this is the output that you’ll get:
I have uploaded this project on Github, so you guys can check it out.
If you guys have any question, please leave a comment.