Sunday, 24 September 2017

Integrate google map SDK for swift in iOS - Tutorial



How to create Google map for swift in iOS - Tutorial


Introduction:

In this tutorial we will learn how to integrate or add Google map SDK for swift in our iOS app project. Google map provides lots of options to the developer if the app want to show the location on map, navigation routes etc., because Google map is the most common map used by the people around the globe. So let start the tutorial.

Steps to integrate or add Google map SDK:

Step 1: Create a new single view application project and name it as "GoogleMap-Tutorial".

Note: If you are not logged in then please login to your Gmail or Google account.

Step 3: Click on "GET A KEY" button, a pop up will appear. Create a new project or use already existing project. After this click on "Enable API" button.

Get A key Google Map SDK iOS
Get A key Google Map SDK 

Create new project Google map SDK
Create new project to integrate Google map SDK
Step 4: You will get API key and copy it to safe location

Google map API key

Step 5: At this moment we have API key, now time to download SDK and install it into our project. Select "GUIDES" tab. 


Step 6:  There are two options to install the SDK, manually or using pods. We will prefer pods as it is more convenient way to upgrade to latest version of SDK. If you are not familiar with installation of pods, you can have a look at below link that explain how to install pods on mac.


Step 7: Open Terminal, and type command

Creating podfile for the project
Creating podfile for the project
The path above is the location of your project until "GoogleMap-Tutorial.xcodeproj".

Step 8: Create podfile using the command "touch podfile"
Coomand to create podfile xcode
Command to create podfile 
Step 9: Adding pod of Google map iOS SDK. In terminal open pofile using command "open -e podfile"

Opening podfile so taht we can write all the pods our application required to indatll
Opening podfile
Step 10: A podfile will be opened up in TextEdit and you can write pod to be installed in it and then save it. Then run the command "pod install". Shown in images below
Adding Google map SDK pod to our podfile
Editing podfile

Installing pods using command "pod install"
Installing pods using command "pod install"
 Step 11: After successful installation you will see message on terminal "Please close any current Xcode sessions and use `GoogleMap-Tutorial.xcworkspace` for this project from now on."

Step 12: Open ".xcworkspace" file. Don't use ".xcodeproj" file to open the project now onward.

Step 13: Open ViewController.swift and add following code to it.



Step 14: Check that you replaced the API key with your own API key, otherwise the map will not show on the screen. Run your app and you will see map is showing on the simulator/ device.

Google map showing on iPhone simulator

Where to go from here: 

In this tutorial you learned, how to configure Google map SDK in swift for iOS. In the future tutorials, we will cover how to add custom markers and draw poly lines / routes on Google map in swift. Hope the tutorial helped in setting up the Google map SDK for swift in iOS.
Download the source code from here

No comments:
Write comments