6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Maps swift2.0

Posted at

Dependencies

swift >= 2.0
Deployment Target == 9.1

Google Maps SDK for IOS

  1. API Keyの取得
  2. Google Maps SDK のインストール

Build Settings > Build Options > Enable Bitcode をNoにする。
( error: linker command failed with exit code 1 )

AppDelegate.swift
import UIKit
import GoogleMaps

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?
  let cGoogleMapsAPIKey = "==API_KEY=============================="

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    GMSServices.provideAPIKey(cGoogleMapsAPIKey)
    return true
  }

  func applicationWillResignActive(application: UIApplication) {}
  func applicationDidEnterBackground(application: UIApplication) {}
  func applicationWillEnterForeground(application: UIApplication) {}
  func applicationDidBecomeActive(application: UIApplication) {}
  func applicationWillTerminate(application: UIApplication) {}
}
ViewController.swift
import UIKit
import GoogleMaps

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    let camera = GMSCameraPosition.cameraWithLatitude(-33.868,
      longitude:151.2086, zoom:6)
    let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
    
    let marker = GMSMarker()
    marker.position = camera.target
    marker.snippet = "Hello World"
    marker.appearAnimation = kGMSMarkerAnimationPop
    marker.map = mapView
    
    self.view = mapView
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }
}
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?