MapboxのMap Matchingを使ってみる

Javascript

Mapbox Map Matching API は、GPSの誤差などで道からずれている移動データを道なりにしてくれるAPIです。

https://www.mapbox.com/help/define-map-matching/

調査で使ってみます。
結論から言うと、あまりいいデータになりませんでした。
量が少ないのかな??

とはいえ、やってみたことをメモとして記録しておきます。

まずは、下記のように横浜駅から弊社への歩きのデータを普通にMap上にポリラインで描画すると、次のようになります。

map_matching_before.png

これを下記のAPIドキュメントを参考にしながらMap MatchingのAPIから結果を取得してみます。
https://www.mapbox.com/api-documentation/#map-matching

結果を取得するURLは次のようになります。

https://api.mapbox.com/matching/v5/mapbox/walking/139.620905,35.4675961;139.6215341,35.4664734;139.6213571,35.4673672;139.6213627,35.4673691;139.6213261,35.4673446;139.6213702,35.4673721;139.6213532,35.4673546;139.6217172,35.4666922;139.6217172,35.4666922;139.6215815,35.4666787;139.6210947,35.4666536;139.6209621,35.4668035;139.6216843,35.4666219;139.6209323,35.4665434;139.6213187,35.4660293;139.6209681,35.4668535.json?access_token=ひみつ

Access Tokenは別途Mapboxで登録して取得してください。

 {
  "matchings": [
    {
      "confidence": 2.7299273952507974e-12,
      "geometry": "mgnwEavdsYbAH@MVAEcB\\s@R?fA`AgAaAS?]r@YOIPBRBFCICQHQXN\\s@R?\\Z??JHfA`A@V_@v@g@i@GGuAqA\\s@R?h@d@fA`A@V_@v@MOLNATTLFNr@lCPIy@cD|@uBEE{AqAsAzC",
      "legs": [
        {
          "summary": "",
          "weight": 139.2,
          "duration": 139.2,
          "steps": [],
          "distance": 193.4
        },
        {
          "summary": "",
          "weight": 84,
          "duration": 84,
          "steps": [],
          "distance": 116.6
        },
        {
          "summary": "",
          "weight": 6.7,
          "duration": 6.7,
          "steps": [],
          "distance": 9.4
        },
        {
          "summary": "",
          "weight": 2.9,
          "duration": 2.9,
          "steps": [],
          "distance": 4
        },
        {
          "summary": "",
          "weight": 3.4,
          "duration": 3.4,
          "steps": [],
          "distance": 4.8
        },
        {
          "summary": "",
          "weight": 6.2,
          "duration": 6.2,
          "steps": [],
          "distance": 8.6
        },
        {
          "summary": "",
          "weight": 62.8,
          "duration": 62.8,
          "steps": [],
          "distance": 87.2
        },
        {
          "summary": "",
          "weight": 0,
          "duration": 0,
          "steps": [],
          "distance": 0
        },
        {
          "summary": "",
          "weight": 6.1,
          "duration": 6.1,
          "steps": [],
          "distance": 8.5
        },
        {
          "summary": "",
          "weight": 88.9,
          "duration": 88.9,
          "steps": [],
          "distance": 120.7
        },
        {
          "summary": "",
          "weight": 4,
          "duration": 4,
          "steps": [],
          "distance": 5.5
        },
        {
          "summary": "",
          "weight": 92.5,
          "duration": 92.5,
          "steps": [],
          "distance": 128.3
        },
        {
          "summary": "",
          "weight": 75.6,
          "duration": 75.6,
          "steps": [],
          "distance": 102.4
        },
        {
          "summary": "",
          "weight": 200.3,
          "duration": 200.3,
          "steps": [],
          "distance": 275.4
        },
        {
          "summary": "",
          "weight": 106.3,
          "duration": 106.3,
          "steps": [],
          "distance": 147.6
        }
      ],
      "weight_name": "duration",
      "weight": 878.9000000000001,
      "duration": 878.9000000000001,
      "distance": 1212.3999999999999
    }
  ],
  "tracepoints": [
    {
      "alternatives_count": 0,
      "waypoint_index": 0,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.620974,
        35.467588
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 1,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621427,
        35.466538
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 2,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621488,
        35.467334
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 3,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621391,
        35.467305
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 4,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621349,
        35.467293
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 5,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621399,
        35.467308
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 6,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621488,
        35.467334
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 7,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621621,
        35.46675
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 8,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621621,
        35.46675
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 9,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621565,
        35.466689
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 10,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621048,
        35.466684
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 11,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621086,
        35.466723
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 12,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621568,
        35.466693
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 13,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.620918,
        35.466552
      ]
    },
    {
      "alternatives_count": 0,
      "waypoint_index": 14,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.621361,
        35.466003
      ]
    },
    {
      "alternatives_count": 1,
      "waypoint_index": 15,
      "matchings_index": 0,
      "name": "",
      "location": [
        139.620989,
        35.466881
      ]
    }
  ],
  "code": "Ok"
 }

描画してみると、次のようになります。

map_matching_after.png

あれれ、ただ単にデータが減っただけみたいですね。
もともとは38個あった緯度経度データが、14個に減っています。

なぜなぜ~。
日本はまだまだデータが少ないからなのか、そもそものデータが少ないのか。
謎ぽよです。

ちょっとわかりませんね。

Hello world!

WordPress へようこそ。これは最初の投稿です。編集もしくは削除してブログを始めてください !