なお、Google Maps SDK for iOS(Ver1.1.0現在)の動作条件は下記の通りとなる。
Xcode 4.5 以降
iOS SDK 6.0 以降
armv7
1. 準備編
(1) Google Developersの、Google Maps SDK for iOSのページにアクセスする。
https://developers.google.com/maps/documentation/ios/start
(1.1) Google Maps SDK for iOSをダウンロードする。
「Getting the Google Maps SDK for iOS」の項のリンクをクリックしてダウンロード。
(2) Google APIs Consoleにアクセスする。
https://code.google.com/apis/console/
(2.1) Services タブを開き、「Google Maps SDK for iOS」のセレクタを ON にする。
(2.2) API Access タブを開き、"Create new iOS key" ボタンをクリック
(2.2.1) アプリのbundle identifierを入力する。(info.plistまたはTATGETSのSummaryのbundle identifierで表示される値と同一)
(2.2.2) 「iOS apps」にbundle identifierが設定されていることを確認。
(2.2.3) 「API key」に表示されている40桁の文字列が、アプリからGoogle MapsにアクセスするAPI Key。
2. コード生成編
(1) Xcodeにてターゲットプロジェクトに、ダウンロードしたGoogle Maps SDK for iOSの中の「GoogleMaps.framework」をFrameworks groupに追加する。
(2) FinderでGoogle Maps SDK for iOSを開き、GoogleMaps.bundleをFrameworks groupに追加する。
(注:Google Developersより、「When prompted, ensure Copy items into destination group's folder is not selected.」)
(3) ターゲットプロジェクトに下記のFrameworkが追加されていなければ追加する。
AVFoundation.framework
CoreData.framework
CoreLocation.framework
CoreText.framework
GLKit.framework
ImageIO.framework
libicucore.dylib
libstdc++.dylib
libz.dylib
OpenGLES.framework
QuartzCore.framework
SystemConfiguration.framework
(4) Default Architecturesはarmv7が使用でき、armv7sは使用できないので注意すること。
(5) TARGETSのBuild Settingsの、Other Linker Flags セクションに、「 -ObjC 」を追加する。
(6) AppDelegate.mを修正。
(6.1) GoogleMapsのヘッダファイルをインポートする。
#import <GoogleMaps/GoogleMaps.h>
(6.2) application:didFinishLaunchingWithOptionsメソッドで、API Keyを宣言する。
[GMSServices provideAPIKey:@"YOUR_API_KEY"];
(7) 基本的なGoogle Mapsの表示
#import "YourViewController.h"
#import
@implementation YourViewController {
GMSMapView *mapView_;
}
// You don't need to modify the default initWithNibName:bundle: method.
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.12345
longitude:123.4567
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(33.12345, 123.4567);
options.title = @"東京";
options.snippet = @"hogehoge";
[mapView_ addMarkerWithOptions:options];
}
(8) その他のGoogle Mapsの表示
オーバレイ表示、航空地図、ハイブリッド表示などがある。ダウンロードしたGoogle Maps SDK for iOSの中に、デモプロジェクトがバンドルされているので、そちらを参照のこと。
参考記事:
https://developers.google.com/maps/documentation/ios/