Dependencies
swift >= 2.0
Deployment Target == 9.1
- API Keyの取得
- 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()
}
}