Вопрос

I have a number of target points on the map and a source location. I need to find the target point closest to the source location. The trick here is that "closest" means the shortest route. I can't use a simple crow fly distance.

This is essentially a one-to-many routing problem. I can get the answer by running a routing API call for each pair of points but that would be too slow and will blow up API usage.

  1. Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)?
  2. If yes, then what are the limits to the number of points, the request frequency, etc?
  3. If no, is there another service that can do it?
  4. Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
Это было полезно?

Решение

You should take a look to Distance Matrix Service

You can specify a starting point and an end point (even intermediate waypoints), then get the distance in kilometers / miles by route.


To answer your questions :

Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)
Yes you can, just use the service given below

If yes, then what are the limits to the number of points, the request frequency, etc?
To quote the Usage limits and requirements :

The following usage limits are in place for the Distance Matrix service:

  • Maximum of 25 origins or 25 destinations per request; and
  • At most 100 elements (origins times destinations) per request.
Requests are also rate limited. If too many elements are requested within a certain time period, an OVER_QUERY_LIMIT response code will be returned.


Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
I'm not sure what you really want, but you can define a point as "source location", then load it (from SQL, KML etc...), then load the targets and call the service to find which one is the closest.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top