LoginSignup
10
10

More than 5 years have passed since last update.

Google map SDK for iOSで経路検索を行う。

Last updated at Posted at 2017-03-27

Google map SDK for iOS

iPhone で地図系アプリを作成する場合は、Google map SDK for iOSを使い地図をアプリに表示しますが、経路検索のAPIがGoogle map SDK for iOSには用意されておりません。
ですのでスクラッチで実装しなければなりませんが、GETで取得して取得した値を経路検索のデーターに用いることは結構骨が折れます、

そこで簡単に開始地点から、目的地までの最短の経路を表示することができるライブラリーがありますのでそちらを使用します。

下記 git hub に上がってるライブラリーをクローンもしくわ、ダウンロードします。

Git hub keisukeYamagishi

sshにてクローンする場合

git@github.com:keisukeYamagishi/Direction.git

https にてクローンする場合

https://github.com/keisukeYamagishi/Direction.git

cocoapods でインストールすることもできます。

$ pod init
$ vi ./Podfile 
target 'Target Name' do
  pod 'Direction'
end
$ pod setup
$ pod install

そのまま再生ボタンか、⌘+ Rでビルドできると思いますので、

ビルドしていただくと下記画像のように起動時に指定された軽度、緯度で経路を表示することができます。

Sample Code



let direction = Direction(from:"35.6775602107869,139.692658446729",to: "35.707848364433,139.701456092298",mode: .walking)
direction.directionCompletion(handler: { (route) in

    for route in route.routes {
        self.mapView.addDirection(path: (route?.overview_polyline?.points)!)
    }

}) { (error) in
    print (error)
}
10
10
2

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