Find nearest X?

If I want to find the nearest thing (supermarket, brewery, hospital, etc) from a point, what should I do?

I know I can use the POIs service and give a bounding box, but I’d prefer something less wonky, such as a single point. Even then, I don’t really want to have to give a point and a radius, get a list of all the matching items, and sort through them all looking for the one with the shortest distance. Even worse, what if the shortest distance is only as the crow flies, but not shortest distance by roads/other paths? I guess that last bit doesn’t really matter.

Hey,

I think searching for the nearest thing is a bit vague - what would a “thing” be? A street lamp? A pedestrian crossing? A tree? If you’re looking for POIs then although this is not the intended use, you can re-purpose the POI service for this:

{"request":"pois","geometry":{"buffer":100,"geojson":{"type":"Point","coordinates":[9.17736992239952,48.78049061818563]}},"limit":2,"sortby":"distance"}

For some reason, the limit needs to be one higher than the actual number of objects you want.
I have opened an issue regarding this.

Best regards

1 Like

I am currently using the POI service with a filter for category ids to find the nearest thing, thing being supermarket, hospital, whatever my options are from the Places list. Sorting by distance and setting the limit to 2 sounds like the fix I was looking for, thank you.

Does it have a distance limit? What exactly does the buffer do?

Thanks for the tip on the limit+1, that would’ve thrown me for a loop.

Hey,

the buffer limits the returned results to an area around the point with radius of the buffer.

I assume there is a distance limit, @takb should know more.

Best regards

1 Like

Ah, perfect. In meters I assume. Surprised it’s called buffer and not just radius, to be more clear.

I’d assume that this might be because it also applies to a polygon - I am not sure though. Documentation for the endpoint is lacking a bit in clarity, unfortunately :frowning:

The limit is 2000m to be exact. Not sure if it is in the docs, but you get a proper error message stating the max buffer if you go over it, so it’s easy to find out :wink:

3 Likes