2
0

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 3 years have passed since last update.

Amazon Location Serviceを試してみる

Last updated at Posted at 2021-06-17

Amazon Location Serviceについて

概要

一言で言うと、位置情報機能を提供するAWSのサービスです。

以下公式説明

Amazon Location Service は、手頃な料金のデータ、トラッキング、ジオフェンス機能、さらには AWS のサービスとのネイティブ統合を提供するため、カスタム開発に高額なコストをかけることなく、洗練された位置情報対応アプリケーションを迅速に構築できます。お客様は、Amazon Location を使用して位置情報データの制御を保持し、独自のデータをサービスにより取得したデータと組み合わせることができます。Amazon Location Service は、信頼できるグローバルプロバイダーである Esri や HERE の高品質なデータを利用して、コスト効率の高い位置情報サービス (LBS) を提供しています。

できること(機能)

  • マップ

    • 位置情報プロバイダのEsriHEREのさまざまなスタイルのマップタイルを提供しているので、ユーザは自分のユースケースに適したマップのスタイルを選択することができる。
    • SDKなどを使用し、自らのアプリケーションにマップを追加することができる。
  • 場所

    • 緯度経度←→住所の変換を提供する。緯度経度を入力すると住所を返すような機能をアプリケーションに組み込める。
      • 住所→緯度・経度 :ジオコーディング
      • 緯度・経度→住所 :リバースジオコーディング
  • ルート

    • 出発地と目的地の間の移動距離、移動時間、道順を特定の移動制限(トラック用モード、車体寸法、回避など)を付けてリクエストできる。
    • EsriとHereから取得したルーティングデータを提供しており、最新の道路情報や交通情報に基づく正確な移動時間の予測を得ることができる。
  • トラッキング

    • トラッキング対応のアプリケーションを実行しているデバイスの過去と現在の位置情報を取得できる。
  • ジオフェンシング

    • 追跡対象のデバイスがあらかじめ定義した地理的境界に出入りしたときに検知し、対応できる。
    • entryイベント・exitイベントをAmazon EventBridgeに送信し、アクションをトリガーできる。

試してみる

ルート機能を使用して、東京駅からスカイツリーまでのルートを検索します。

ジオコーディング

場所機能のジオコーディングから座標を検索します。

そのために、まず「Place index」を作成します。
Amazon Location Serviceの左側メニューから「Place indexes」を選択し、「Create place index」からplace indexを作成します。

ALS3.png

それぞれの設定項目は

  • Name:test-placeindex
  • Data providers:HERE
  • Data storage options:No, single use only
  • Pricing Plan use-case:Yes

としました。

最後のチェックボックスにチェックを付け、作成します。

ALS2.png

今回は簡単に試してみるのが目的なので、AWS CLIでコマンドを打ち、座標を検索します。

まずは"東京駅"を検索します。

aws location search-place-index-for-text \
    --index-name test-placeindex \
    --text "東京駅" \ 
    --max-results 5 > result.json
実行結果
result.json
{
    "Results": [
        {
            "Place": {
                "AddressNumber": "1",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.76544,
                        35.68155
                    ]
                },
                "Label": "東京都千代田区丸の内1丁目9-1東京駅",
                "Municipality": "千代田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "AddressNumber": "5",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.76482,
                        35.68221
                    ]
                },
                "Label": "東京都千代田区丸の内1丁目6-5東京駅",
                "Municipality": "千代田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "AddressNumber": "1",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.76729,
                        35.68096
                    ]
                },
                "Label": "東京都千代田区丸の内1丁目9-1東京駅",
                "Municipality": "千代田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "AddressNumber": "1",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.76875,
                        35.68011
                    ]
                },
                "Label": "東京都千代田区丸の内1丁目9-1東京駅一番街",
                "Municipality": "千代田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "AddressNumber": "1",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.76862,
                        35.68272
                    ]
                },
                "Label": "東京都千代田区丸の内1丁目9-1東京駅 斑鳩",
                "Municipality": "千代田区",
                "Region": "東京都"
            }
        }
    ],
    "Summary": {
        "DataSource": "Here",
        "MaxResults": 5,
        "ResultBBox": [
            139.76482,
            35.68011,
            139.76875,
            35.68272
        ],
        "Text": "東京駅"
    }
}

続いて"東京スカイツリー"を検索します。

aws location search-place-index-for-text \
    --index-name test-placeindex \ 
    --text "東京スカイツリー"  \
    --max-results 5 > result.json
実行結果
result.json
{
    "Results": [
        {
            "Place": {
                "AddressNumber": "2",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.81075,
                        35.71001
                    ]
                },
                "Label": "東京都墨田区押上1丁目1-2東京スカイツリー",
                "Municipality": "墨田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.81009,
                        35.70959
                    ]
                },
                "Label": "東京都墨田区業平1丁目19東京スカイツリー西交差点",
                "Municipality": "墨田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.8138,
                        35.71086
                    ]
                },
                "Label": "東京都墨田区押上1丁目8東京スカイツリー東交差点",
                "Municipality": "墨田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "AddressNumber": "2",
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.81074,
                        35.71007
                    ]
                },
                "Label": "東京都墨田区押上1丁目1-2東京スカイツリー4階インフォメーションカウンター",
                "Municipality": "墨田区",
                "Region": "東京都"
            }
        },
        {
            "Place": {
                "Country": "JPN",
                "Geometry": {
                    "Point": [
                        139.80858,
                        35.71056
                    ]
                },
                "Label": "東京都墨田区押上2丁目1角吉 東京スカイツリー駅前店",
                "Municipality": "墨田区",
                "Region": "東京都"
            }
        }
    ],
    "Summary": {
        "DataSource": "Here",
        "MaxResults": 5,
        "ResultBBox": [
            139.80858,
            35.70959,
            139.8138,
            35.71086
        ],
        "Text": "東京スカイツリー"
    }
}

それぞれの座標がわかりました。

場所 経度 緯度
東京駅 139.76544 35.68155
東京スカイツリー 139.81075 35.71001

この座標からルート検索を行います。

ルート機能

ルート機能を試す為に「Route Calculator」を作成します。

Amazon Location Serviceの左側メニューから「Route Calculators」を選択し、「Create route calculator」からroute calculatorsを作成します。

ALS4.png

設定項目は

  • Name:test-routecalculator
  • Data providers:HERE
  • Pricing Plan use-case:Yes

としました。

ALS1.png

先ほど入手した座標を使い、コマンドを打ちます。
今回は徒歩での計測とするため、
--travel-mode "Walking"
というオプションを含み、徒歩を指定します。

aws location calculate-route \
    --calculator-name test-routecalculator \
    --departure-position 139.76544 35.68155 \
    --destination-position 139.81075 35.71001 \
    --travel-mode "Walking" > result.json
実行結果
result.json
{
    "Legs": [
        {
            "Distance": 5.775,
            "DurationSeconds": 5848,
            "EndPosition": [
                139.8108003,
                35.7096611
            ],
            "StartPosition": [
                139.76559,
                35.6818956
            ],
            "Steps": [
                {
                    "Distance": 0.101,
                    "DurationSeconds": 111,
                    "EndPosition": [
                        139.765913,
                        35.682719
                    ],
                    "StartPosition": [
                        139.76559,
                        35.681896
                    ]
                },
                {
                    "Distance": 0.263,
                    "DurationSeconds": 272,
                    "EndPosition": [
                        139.767693,
                        35.684397
                    ],
                    "StartPosition": [
                        139.765913,
                        35.682719
                    ]
                },
                {
                    "Distance": 0.065,
                    "DurationSeconds": 74,
                    "EndPosition": [
                        139.768394,
                        35.684249
                    ],
                    "StartPosition": [
                        139.767693,
                        35.684397
                    ]
                },
                {
                    "Distance": 2.292,
                    "DurationSeconds": 2298,
                    "EndPosition": [
                        139.786295,
                        35.697355
                    ],
                    "StartPosition": [
                        139.768394,
                        35.684249
                    ]
                },
                {
                    "Distance": 1.57,
                    "DurationSeconds": 1579,
                    "EndPosition": [
                        139.796174,
                        35.708811
                    ],
                    "StartPosition": [
                        139.786295,
                        35.697355
                    ]
                },
                {
                    "Distance": 0.247,
                    "DurationSeconds": 255,
                    "EndPosition": [
                        139.798521,
                        35.70771
                    ],
                    "StartPosition": [
                        139.796174,
                        35.708811
                    ]
                },
                {
                    "Distance": 0.927,
                    "DurationSeconds": 937,
                    "EndPosition": [
                        139.808535,
                        35.708863
                    ],
                    "StartPosition": [
                        139.798521,
                        35.70771
                    ]
                },
                {
                    "Distance": 0.096,
                    "DurationSeconds": 108,
                    "EndPosition": [
                        139.808491,
                        35.709718
                    ],
                    "StartPosition": [
                        139.808535,
                        35.708863
                    ]
                },
                {
                    "Distance": 0.214,
                    "DurationSeconds": 214,
                    "EndPosition": [
                        139.8108,
                        35.709661
                    ],
                    "StartPosition": [
                        139.808491,
                        35.709718
                    ]
                }
            ]
        }
    ],
    "Summary": {
        "DataSource": "Here",
        "Distance": 5.775,
        "DistanceUnit": "Kilometers",
        "DurationSeconds": 5848,
        "RouteBBox": [
            139.76559,
            35.6818956,
            139.8108003,
            35.709718
        ]
    }
}

一部切り取り

    "Summary": {
        "DataSource": "Here",
        "Distance": 5.775,
        "DistanceUnit": "Kilometers",
        "DurationSeconds": 5848,
        "RouteBBox": [
            139.76559,
            35.6818956,
            139.8108003,
            35.709718
        ]
    }

スカイツリーまで9ステップあるようです。この座標をたどれば約5.7km,約1時間40分で着くみたいです。
(結構遠いですね。。。)

まとめ

Amazon Location Serviceの場所機能とルート機能を試してみました。かなり簡単に位置情報機能が使えるなという印象を持ちました。
精度はしっかりと見ていないのですが、今回出力された座標を別のサービスで検索するとだいたいあっていたので悪くはないのかなと思います。
トラッキングやジオディフェンシングも面白そうな機能なので、気が向いたら試してみたいです。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?