mendhak / gpslogger

:satellite: Lightweight GPS Logging Application For Android.
https://gpslogger.app
Other
2k stars 609 forks source link

Custom URL upload to MapBox not working #1040

Closed arugifa closed 1 year ago

arugifa commented 1 year ago

I am trying to use the custom URL feature in order to update a dataset on MapBox.com, but without any success until now.

I think it should be possible, but I might do something wrong.

According to MapBox's documentation, I should send a PUT request with a new feature to an already created dataset. So here is how I configured GPS Logger:

URL: https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/%TIMESTAMP?access_token={access_token} HTTP Body: {"id": "%TIMESTAMP", "type": "Feature", "geometry": { "type": "Point", "coordinates": [ %LAT, %LON ] } } HTTP Headers: Content-Type: application/json HTTP Method: PUT

I validated SSL certificate with success. But when looking in the logs, I can see:

12:58 HTTP request complete with unexpected response code Response{protocol=http/1.1, code=442, message=Unprocessable Entity, url=https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/1672826320?access_token={access_token}}
12:58 Custom URL-Could not upload the file

Have you already tried to upload GPS points to Mapbox?

Also, not sure if the HTTP response is truncated. It might contain more information about the problem. But it looks like my JSON payload is somehow invalid :thinking:

mendhak commented 1 year ago

I've never tried with Mapbox, but I signed up just now to try it. Here's what worked for me.

URL

https://api.mapbox.com/datasets/v1/xxxxxxxxxxxx/xxxxxxxxxxxxxxxx/features/%TIMESTAMP?access_token=sk.xxxxxxxxxxxxxxxxx

In your example did you substitute the username and datasetid and access token with your own values?

HTTP Body

{"id": "%TIMESTAMP", "type": "Feature", "geometry": { "type": "Point", "coordinates": [ %LON, %LAT ] }, "properties":{}}

I think that this needs to be long-lat, because it's GeoJSON.

HTTP Headers

Content-Type: application/json

HTTP Method

PUT

image

arugifa commented 1 year ago

Wow, thanks a lot for the test, and your quick answer! :star_struck:

I gave a try to reversing latitude-longitude order, but it didn't help (to solve the HTTP request failure; but you were right, I was setting them in the wrong order).

So I did like you, and also added an empty properties dictionary to the HTTP body, and it worked! :smiley:

Hope it will help other people who want to use MapBox too.

Thanks a lot for your help, work, and great app :)

mendhak commented 1 year ago

No worries, good to know.