Filter POIs that are close to a route

I have a list of Points-of-Interest (e.g. car rest areas).

The user selects the Starting Point and the Ending Point. This generates a route.

  1. How can I programmatically filter the POIs that are close (e.g. 50 meters distance from the road) that route?
  2. Can Google Maps SDK or OSRM offer this functionality?

Thank you, Nick

Upvotes: 0

Views: 348

Answers (1)

Alex
Alex

Reputation: 649

1. You have to find the distance from one POI to the road.

In order to accomplish this, you have to store your road in a mathematical fashion:

  • You can sample equidistant points of your road and store them in an array (more practical, less precise) and then calculate the distance of the POI from every point in the array, then save the minor result and repeat the whole process for every POIs.
  • You can store a road in a function (more and more complex, but more precise). Now that you have this function, you can calculate same distance from your POI, take the minimum value and repeat for all POIs.

2. Google Distance Matrix can actually do this

With this Api you can calculate distance till 2500 origins * destinations points. The result will give you an array of rows, with each row corresponding

to an origin, and each element within that row corresponds to a pairing of the origin with a destination value.

Example of a request:

https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=32.777211,35.021250&destinations=32.778663,35.015757&key=YOURAPIKEY

This is very useful to your goal, because lets you specify more than one points of which calculates distance.

Upvotes: 1

Related Questions