Simplified iOS

  • Home
  • About
  • Contact
  • Advertise
  • Write for Us

Google Maps iOS Tutorial – Implementing Google Maps using Swift

June 3, 2017 by Belal Khan 2 Comments

Do you want to learn implementing Google Maps in our iOS Application. So here is Google Maps iOS Tutorial. Today we will learn how to add Google Maps in our iOS Application using Swift. So lets start.

Contents

  • 1 Google Maps iOS Tutorial Video
  • 2 Creating a new Xcode Project
  • 3 Adding Google Maps using CocoaPods
  • 4 Getting an API Key
  • 5 Implementing Google Maps in Xcode Project
    • 5.1 Share this:
    • 5.2 Related

Google Maps iOS Tutorial Video

  • Here is the video tutorial about implementing  Google Maps to iOS App, you can go with it as well.

Creating a new Xcode Project

  • Now the first thing is creating a new Xcode Project. So I am creating GoogleMapsExample.

google maps ios tutorial

  • Now once the project is loaded we will first add Google Maps SDK using CocoaPods.

Adding Google Maps using CocoaPods

  • Right click on your project and select New File… as shown in the image.

new file

  • Now create an Empty file named Podfile.
  • Inside the Podfile write the following code.
source 'https://github.com/CocoaPods/Specs.git'
target 'GoogleMapsExample' do
pod 'GoogleMaps'
pod 'GooglePlaces'
end
  • In the above code GoogleMapsExample is my project name, so make sure it matches with your project name.
  • Now navigate to your project directory in terminal and run the command pod install.
  • It will download and install the Google Map Dependencies.
  • Now close the Xcode Project and open yourproject.xcworkspace. For the detail steps about using CocoaPods you can check the last tutorial about Google Signin in Swift.
  • Now we need an API Key.

Getting an API Key

  • Go to this link and click on GET A KEY.

getting api key

  • Now it will ask you to select a project. So select a project and Enable the API.

enable google maps sdk

  • After clicking Enable API you will get you API Key.

enabling api

  • Now copy the API from here.

Implementing Google Maps in Xcode Project

  • Now come to the Xcode project and open AppDelegate.swift. Here you need to provide the API key as I provided in the following code snippet.
//
//  AppDelegate.swift
//  GoogleMapsExample
//
//  Created by Belal Khan on 03/06/17.
//  Copyright © 2017 Belal Khan. All rights reserved.
//

import UIKit

//you should import google maps
import GoogleMaps

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        //this line should be added
        GMSServices.provideAPIKey("AIzaSyCJV5rHYEfQISiDi1qD_AIFg338KDFlCJM")

        // Override point for customization after application launch.
        return true
    }
  • Now come to ViewController.swift.
//
//  ViewController.swift
//  GoogleMapsExample
//
//  Created by Belal Khan on 03/06/17.
//  Copyright © 2017 Belal Khan. All rights reserved.
//

import UIKit
import GoogleMaps

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //creating a camera
        let camera = GMSCameraPosition.camera(withLatitude: 23.431351, longitude: 85.325879, zoom: 6.0)
        
        //this is our map view
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        
        //adding mapview to view
        view = mapView
        
        //creating a marker on the map
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 23.431351, longitude: 85.325879)
        marker.title = "Ranchi, Jharkhand"
        marker.map = mapView
        
    }

}

  • Now run the application in Simulator.
Google Maps iOS Tutorial

Google Maps iOS Tutorial

  • Bingo! It is working absolutely fine.

So thats all for this Google Maps iOS Tutorial friends. If you are having any queries or confusions regarding this Google Maps iOS Tutorial then lets have a discussion on the comment section. And don’t forget to SHARE this post if you found it helpful. Thank You 🙂

Share this:

  • Tweet
  • Share on Tumblr
  • WhatsApp

Related

Filed Under: iOS Development Tutorial Tagged With: google maps ios tutorial, google maps swift

About Belal Khan

I am Belal Khan, I am currently pursuing my MCA. In this blog I write tutorials and articles related to coding, app development, iphone etc.

Comments

  1. nilesh sinha says

    July 5, 2017 at 5:36 am

    Thank you Belal for Wonderful tutorial

    Reply
  2. Daniel says

    August 7, 2017 at 2:11 pm

    Hello,
    I want to us, is it possible to measure a distance using google API in iOS?
    Thank You

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *




About Me

belal khan simplified ios

Hello I am Belal Khan, founder and owner of Simplified iOS. I am currently pursuing MCA from St. Xavier's College, Ranchi. Apart from my academic I am a blogger, I run various websites and majority of them are about coding and development.

Connect with Me

Follow Simplified iOS

Simplified iOS

Popular Posts

  • Swift SQLite Tutorial for Beginners – Using… (99,467)
  • Swift PHP MySQL Tutorial – Connecting iOS App… (98,354)
  • UIWebView Example to Load URL in iOS using Swift in Xcode (80,016)
  • Download Full High Sierra Installer to Create Bootable USB (70,346)
  • Xcode Login Screen Example using Swift 3, PHP and MySQL (67,312)
  • How to Format USB on Mac? Formatting External Hard… (61,392)
  • Swift JSON Tutorial – Fetching and Parsing… (59,414)
  • Firebase Realtime Database Tutorial for Swift using Xcode (53,721)
  • iOS Registration Form Example using PHP and MySQL (48,989)
  • Xcode Text Field Tutorial for iOS Application using Swift (41,228)




About

Simplified iOS is a blog where you can find latest tutorials related to coding and app development for iphone and MAC OS. Here you can get Simplified iPhone, iPad and Mac OS development tutorial to know the things about Apple Development from basics to advanced level.

Quick Links

  • Advertise
  • Contact
  • Disclaimer
  • Privacy Policy
  • Write for Us

Copyright © 2017 · Simplified iOS· All rights Reserved. And Our Sitemap.All Logos & Trademark Belongs To Their Respective Owners·