LoginSignup
1
2

More than 5 years have passed since last update.

FileMaker:JSON:地図上の距離を求める

Last updated at Posted at 2018-02-20

複数拠点を移動するときの、拠点間の距離を求めたい

Google Maps Distance Matrix API を使う

Distance Matrix API
API-Keyを取得する->https://developers.google.com/maps/documentation/distance-matrix/start?hl=ja

出発地と到着地の住所フィールドを作る

  • 変数を設定[$dept;値:出発地住所]
  • 変数を設定[$goal;値:拠点住所] *複数ある場合は"|"でセパレートしておく
GoogleへのリクエストURLはこんな感じ
https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&avoid=highways&origins=" & $dept   & "&destinations=" & $goal & "&key=API-KEY

デベロッパーガイドより

units=metric
メートル法表記
avoid=highways
高速使わない

これで帰ってくるJSONがこちら

Sample
{
   "destination_addresses" : [ "出発地の住所" ],
   "origin_addresses" : [ "拠点住所" ],
"rows" : 
    [
        {
            "elements" : 
            [
                {
                    "distance" : 
                    {
                        "text" : "12.2 km",
                        "value" : 12244
                    },
                    "duration" : 
                    {
                        "text" : "29 mins",
                        "value" : 1711
                    },
                    "status" : "OK"
                }
            ]
        },
        {
            "elements" : 
            [
                {
                    "distance" : 
                    {
                        "text" : "4.5 km",
                        "value" : 4535
                    },
                    "duration" : 
                    {
                        "text" : "13 mins",
                        "value" : 806
                    },
                    "status" : "OK"
                }
            ]
        },
        {
            "elements" : 
            [
                {
                    "distance" : 
                    {
                        "text" : "12.8 km",
                        "value" : 12826
                    },
                    "duration" : 
                    {
                        "text" : "40 mins",
                        "value" : 2425
                    },
                    "status" : "OK"
                }
            ]
        }
    ],
    "status" : "OK"
}

あとはJSONgetElementでほしいところのオブジェクトを指定してあげればいいんですが、結構試行錯誤

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