LoginSignup
11
11

More than 5 years have passed since last update.

Google Maps SDK for iOSの導入手順

Last updated at Posted at 2015-11-20

久しぶりに使おうと思ったら手順がだいぶ変わっていたのでGoogle Maps SDKのダウンロード、APIキーの取得、サンプルを動かすところまでをメモ。
(基本的にGoogle Maps SDK for iOSのGetting Startedの内容。)

開発環境:Xcode7.1.1

手順

1 CocoaPodをインストールする 

$ sudo gem install cocoapods

2 Podfileを作成する

GoogleMapSDKを使いたいXcodeのプロジェクト内にPodfileを作成する。
(.xcodeprojと同列に作成)

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
pod 'GoogleMaps'

3 GoogleMapSDKをインストールする

ターミナルでPodfileがある階層に移動して、以下のコマンドを実行。

$pod install

4 iOS API keyを取得する

4.1 Google Developers Consoleを開く
4.2 画面右上部にある「プロジェクトを選択してください」を押下し、プルダウンにある「プロジェクトの作成...」を押下して、新しいプロジェクトを作成する
4.3 ダッシュボード内にある「Google APIを利用する」を押下し、API Managerのページへ移動
4.4 左メニューの「認証情報」を押下し、認証情報画面を開く
4.5 認証情報タブの『認証情報を追加』ボタンを押下し、「API キー > iOSキー」を押下
4.6 iOS APIキーの作成画面で「作成」ボタンを押下。
4.7 APIキーが取得できる。

5 Google Developers ConsoleからAPIを有効にする

5.1 Google Developers Consoleを開く
5.2 ダッシュボード内にある「Google APIを利用する」を押下し、API Managerのページへ移動
5.3 左メニューの「概要」を押下し、概要画面を開く(デフォルトはこの画面)
5.4 Google Maps API カテゴリ内の以下二つを有効にする

  • Google Maps SDK for iOS
  • Google Places API for iOS

6 ソースコードにAPIキーを記述する

AppDelegate.m 内に以下を追加する。

GoogleMapsをimportする。

@import GoogleMaps;

application:didFinishLaunchingWithOptions: に以下のコードを記載する
YOUR_API_KEY に4.で取得したAPIキーを記載)

[GMSServices provideAPIKey:@"YOUR_API_KEY"];

7 サンプルコードを動かしてみる

Google Maps SDK for iOSのトップにある Hello MapViewController.m にコピーする

8 Info.plistに設定を追加

8.1 LSApplicationQueriesSchemesを追加し、Typeを Array に設定
8.2 LSApplicationQueriesSchemesの中に以下2つを追加

  • googlechromes
  • comgooglemaps

9 ビルド

ビルドを実行するとGoogleMap上にマーカーの載った画面が表示される。

エラー

その1

一通り設定が終わって、アプリをビルドしたところ以下のようなエラーが出た。

エラー内容

ld: library not found for -lPods

同時に以下のようなWorningが出る。

Target 'Pods' of project 'Pods' was rejected as an implicit dependency for 'libPods.a' because its architectures 'arm64' didn't contain all required architectures 'armv7 arm64'

解決策

Build Settings内のArchitecturesにある「Build Active Architecture Only」をYesに変更する。

1度ビルドが通ると、ここのNoに戻してもビルドは通るようになる。

その2

実機(iPhone5S)でビルドしたところ以下のようなエラーが出た。

ld: '/Users/**/program/Xcode_Test/googlemap_test/googlemaptest/Pods/GoogleMaps/Frameworks/GoogleMaps.framework/GoogleMaps(GMSBillingPointRecorder.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

解決策

BuildSettingsのBuild Optionsにある Enable Bitcodeを「NO」に設定する。

11
11
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
11
11