MapBox map matching api throwing error

707 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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. enter image description here