來抱怨一下,相信大家也是這樣,只要Xcode版本一大改,很多套件都需要更新
以前我是用下載他的sdk裡面的framework檔放進去,但是現在用cocoapods來處理
本篇是用Swift2.0所開發,Object-C的話... 我不會
一、開始Terminal
安裝cocoapods
sudo gem install cocoapods
二、開新專案
開新增案後,在將專案關閉
專案名稱:TestMap
到專案目錄下,新增Podfile檔
以下是內容,編輯完後儲存
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.1' pod 'GoogleMaps'
在用Terminal cd到專案目錄
cd ........./TestMap
在用Terminal,執行以下的指令
pod install
四、取得Google Developer Console Key
點此連結申請
五、最後寫程式
請打開TestMap.xcworkspace
1.AppDelegate.swift
... import GoogleMaps @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. GMSServices.provideAPIKey("key") return true } ... }
2.ViewController.swift
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6) let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera) mapView.myLocationEnabled = true self.view = mapView let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) marker.title = "Sydney" marker.snippet = "Australia" marker.map = mapView } }
3.Run... Finish
參考鏈結:
https://developers.google.com/maps/documentation/ios-sdk/start/
https://www.youtube.com/watch?v=q6tg3gl7CsU
沒有留言:
張貼留言