project-osrm nearest OpenStreetMap point id

574 views Asked by At

I have to find the nearest node (the id) of a geo-spatial point in OpenStreetMap

I can use the official demo api

https://router.project-osrm.org/nearest/v1/foot/13.388860,52.517037

and I have this very nice output:

// 20170831155106
// https://router.project-osrm.org/nearest/v1/foot/13.388860,52.517037

{
    "waypoints": [
        {
            "hint": "DB0KgLNSo4oUAAAAIAAAAAcAAAAAAAAACgAAABAAAAAEAAAAAAAAAK7aAAAATMwAqVghAzxMzACtWCEDAQAPAN1tFXI=",
            "distance": 4.085341,
            "location": [
                13.3888,
                52.517033
            ],
            "name": "Friedrichstra\u00c3\u0178e"
        }
    ],
    "code": "Ok"
}

but that doesn't give me the nearest OSM node id and I can't use "?annotations=true" because I receive this message

https://router.project-osrm.org/nearest/v1/foot/13.388860,52.51703713.388860,52.517037?annotations=true

{'code': 'InvalidQuery',
 'message': 'Query string malformed close to position 37'}
2

There are 2 answers

0
themarex On

This feature is currently being worked on. The PR looks good, but needs some fixes around the edges.

0
Dinesh Sandaruwan On

Try like this..

Example- http://router.project-osrm.org/nearest/v1/driving/79.887810,7.005145?number=3&bearings=90,100

Output-

{
    "waypoints": [
        {
            "nodes": [
                2264199819,
                2045820592
            ],
            "hint": "5c34iGPO-IgIAAAADgAAAAMAAAAAAAAAeOI0QY6li0FoZYRAAAAAAAgAAAAOAAAAAwAAAAAAAADxpQAAAEzMAKlYIQM8TMwArVghAwEA3wrB8JPr",
            "distance": 4.096695475190991,
            "name": "Friedrichstraße",
            "location": [
                13.3888,
                52.517033
            ]
        }
    ],
    "code": "Ok"
}