简体   繁体   中英

MapBox map matching api throwing error

I am using mapbox to display maps in my application. I am displaying user's location as the user moves and to keep the location on the street I am trying to use map box map-matching api. But the api works with the test points in map-matching api, but throws error when i use my actual lat-long points. https://www.mapbox.com/api-documentation/#retrieve-a-match I send the request using

curl -X POST \
--header "Content-Type:application/json"-d @trace.json \
 "https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=<your token here>"

When my trace.json file has the test input mentions in api, i get the result This is trace.json with lat long from the api, and returns result.

{
"type": "Feature",
"properties": {
"coordTimes": [
  "2015-04-21T06:00:00Z",
  "2015-04-21T06:00:05Z"
]
},
"geometry": {
"type": "LineString",
"coordinates": [
  [ 13.418946862220764, 52.50055852688439 ],
  [ 13.419011235237122, 52.50113000479732 ]
]
}
}

But the same trace.json with my lat-long point throws following error.

Error : {"message":"each coordinate must be array with float in-bounds      [longitude, latitude]","code":"InvalidInput"}

{
"type": "Feature",
"properties": {
"coordTimes": [
  "2015-04-21T06:00:00Z",
  "2015-04-21T06:00:05Z"
]
},
"geometry": {
"type": "LineString",
"coordinates": [
    [47.586479, -122.229704],
    [47.578238, -122.209869]
    ]
}
}

can't figure out what's wrong with the request.

The error code you received is the key to the problem. Your "coordinates" data must be in [longitude, latitude] which is the standard for GeoJson .

Error : {"message":" each coordinate must be array with float in-bounds [longitude, latitude] ","code":"InvalidInput"}

To fix, you need to swap around your data for the "coordinates" . As another test you can use GeoJson.io to validate your traces.json , and to verify you have proper input data into your MapMatch tool.

{
  "type": "Feature",
  "properties": {
  "coordTimes": [
  "2015-04-21T06:00:00Z",
  "2015-04-21T06:00:05Z"
  ]
},
  "geometry": {
  "type": "LineString",
  "coordinates": [
    [-122.229704, 47.586479],
    [-122.209869, 47.578238]
  ]
  }
}

See this gist , and the image here for how you can use other tools to validate your original GeoJson. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM