Introduction:
In this tutorial we will learn how to integrate or add Google map SDK for swift language in our iOS app project. Google map SDK for iOS provides lots of options to the developer for example 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 that’s why it’s a better option to use Googel map sdk for iOS while adding maps or navigation in your iOS apps. Please follow the below steps to integrate Google map iOS SDK
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 | |
|
Create new project to integrate Google map SDK |
Step 4: You will get API key and copy it to safe location
Step 5: At this moment we have API key, now time to download SDK and install it into our project. Select “GUIDES” tab.
Installation of Google map SDK in xcode project
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 |
The path above is the location of your project until “
GoogleMap-Tutorial.xcodeproj“.
Step 8: Create podfile using the command “touch podfile”
|
Command to create podfile | | |
Step 9: Adding pod of Google map iOS SDK. In terminal open pofile using command “open -e podfile”
|
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
|
Editing podfile |
|
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.
Where to go from here:
In this tutorial you learned, how to configure Google map iOS SDK in swift for iOS apps. 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 iOS SDK for swift language.
Download the source code from
here