Google Maps SDK for iOSがキタ——(゚∀゚)——!!
2月 22, 2013 コメントをどうぞ
Google Maps API Teamから「使えるようになったぜ」ってメールが着たのでお試し。
前はAPI keyが生成できなかったんだが、はてさて。
Getting Started
ココから順序通りにやってみる。
まずはSDKをダウンロード。なにげにバージョンが1.1.0に上がってるw
API keyを作成
- ココからAPI Projectを作成
- ServicesのペインからGoogle Maps SDK for iOSをONにする
- API AccessのペインからCreate new iOS key…をクリックする
- ダイアログのテキストエリアにSDKを使用するアプリのbundle identifiersを登録する
- CreateをクリックするとAPI keyが作成される
- API AccessのペインのKey for iOS apps (with bundle identifiers)の項目にあるAPI keyがアプリで使用するキーになる
4のbundle identifiersの登録は制限をかけるためのものなので、API keyを使い回す場合は複数登録するのかな。
何も登録しなかったら全てのアプリからAPI keyが使い回せるみたい。
サンプルプロジェクトで確認
ダウンロードしたSDKにサンプルプロジェクトが同梱されているのでAPI keyがちゃんと使えるかどうかだけならこのプロジェクトで試せばいいかな。
SDKDemos/APIKey.hに
const static NSString *APIKey = @"";
があるので、API keyをコピペ。
実行するとサンプルのリストが出てくるので適当に。
MapSampleViewController
ShowcaseSample
CameraSample
サンプルの一覧
- MapSampleViewController
- UISettingsSample
- Map Types
- ResizeMapSample
- CustomMarkerSample
- GroundOverlaySample
- ProjectionSample
- TrafficSample
- ShowcaseSample
- CameraSample
- PolylineSample
- MarkerSample
自前のプロジェクトを起こしてみる
API keyが問題なく作成できたので自前のプロジェクトで試してみる。
- Single View Applicationでプロジェクトを作成
- ダウンロードしたGoogleMaps.frameworkをフォルダごとプロジェクトにコピー
- コピーしたGoogleMaps.frameworkをShow in Finderで開いて、ResourcesフォルダにあるGoogleMaps.bundleをプロジェクトにコピー
- プロジェクトのTargetsのBuild PhasesのLink Binary With Librariesに以下のライブラリを追加
- AVFoundation.framework
- CoreData.framework
- CoreLocation.framework
- CoreText.framework
- GLKit.framework
- ImageIO.framework
- libicucore.dylib
- libstdc++.dylib
- libz.dylib
- OpenGLES.framework
- QuartzCore.framework
- SystemConfiguration.framework
- Build SettingsのArchitecturesをarmv7に変更
- Other Linker Flagsに-ObjCを追加
- AppDelegateあたりで初期化
#import <GoogleMaps/GoogleMaps.h>
application:didFinishLaunchingWithOptions:メソッドで
[GMSServices provideAPIKey:@"YOUR_API_KEY"];
ViewControllerにマップの追加
#import "YourViewController.h" #import <GoogleMaps/GoogleMaps.h> @implementation YourViewController { GMSMapView *mapView_; } // You don't need to modify the default initWithNibName:bundle: method. - (void)loadView { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init]; options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086); options.title = @"Sydney"; options.snippet = @"Australia"; [mapView_ addMarkerWithOptions:options]; }
サンプルコードそのまんまだけど、適当に自分のViewControllerに突っ込んだらマップが表示された。
広告