23
26

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 SDK for iOSを使う

Last updated at Posted at 2013-06-19

###1. API Keyの取得
1. Google Maps SDK for iOSのステータスをonにする

Google APIs Consoleで画面左のServicesを選択し、Google Maps SDK for iOSのステータスをonにする。

2. API Keyを取得

[Google APIs Console](Google APIs Console "https://code.google.com/apis/console/")で画面左のAPI Accessを選択し、Create new iOS keyをクリック。アプリのbundle identifiersを入力し、Createをクリック

###2. SDKの追加
1. Google Maps SDK for iOSダウンロード
Version 1.3.1からSDKをダウンロードする。

2. GoogleMaps.framework追加
GoogleMaps.frameworkフォルダをXcodeのFrameworksにドラッグアンドドロップ。(__Copy items into destination group's folder__にチェックをつける)

3. GoogleMaps.bundle追加
Xcode上で2で追加したGoogleMaps.frameworkを右クリックし、Show In Finderを選択。Resourcesフォルダの中にあるGoogleMaps.bundleをXcodeのFrameworksにドラッグアンドドロップ。__Copy items into destination group's folder__のチェックをはずす)

4. その他のフレームワークを追加
以下のフレームワークを追加。

・AVFoundation.framework
・CoreData.framework
・CoreLocation.framework
・CoreText.framework
・GLKit.framework
・ImageIO.framework
・libc++.dylib
・libicucore.dylib
・libz.dylib
・OpenGLES.framework
・QuartzCore.framework
・SystemConfiguration.framework

5. Build Settingsの変更
TARGETSのBuild Settingsを開き以下の2つを変更

・Architecturesをarmv7に設定
・Other Linker Flagsを-ObjCに設定

6. AppDelegate編集

GoogleMaps.hをインポートし、application:didFinishLaunchingWithOptions:メソッド内で取得したAPI Keyを設定。

AppDelegate.m
# -----------略-----------
#import <GoogleMaps/GoogleMaps.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [GMSServices provideAPIKey:@"AIzaSyB7-kCq7IriVPLeSXo6d3NQ1-s-w86iBB4"];
    return YES;
}
# -----------略-----------

###3. サンプルを動かす

公式にあるサンプルを動かしてみる。

ViewController.m
#import "ViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@interface ViewController ()

@end

@implementation ViewController {
    GMSMapView *mapView_;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.view = mapView_;
    
    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end!

こんな感じのが出来るはず。

googlemap.png

##参照
Google Maps SDK for iOS

23
26
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
23
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?