Answer the question
In order to leave comments, you need to log in
Does the API of Yandex, Google or other maps have a FREE opportunity to calculate the distance between points UNLIMITED?
Hello.
I am hatching the idea of a project - a catalog of objects, where the emphasis will be placed on the location of objects on the map.
A very useful feature would be the ability to sort objects by distance from the specified address.
Question: is it possible to calculate the distance between coordinates in large quantities for FREE using the Yandex or Google API (if not, then other) maps?
That is, the user indicated the location and from this point the distance to the 10 closest objects was found, after which they were displayed in the list, sorted by distance. As the list scrolls, 10 more objects are loaded and the distance is calculated.
I found on the Internet that there is such an opportunity in the Yandex and Google APIs, but it is not clear to what extent this functionality can be used.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Maybe OSM has it .
I wrote my own route calculation algorithm for google maps.
Those. You can put as many points as you want on the map and a route will be drawn from them.
This solution turned out to be 8% more accurate than suggested by google (paths and time are shorter by 8%, because terrain features and other factors are taken into account).
I somehow ported someone's algorithm to JS, the curvature of the ball is taken into account, the coordinates can be used directly from the Google map or Yasha. The result is returned in meters
function calculateTheDistance (shir_A, dolg_A, shir_B, dolg_B) {
lat1 = shir_A * Math.PI / 180;
lat2 = shir_B * Math.PI / 180;
long1 = dolg_A * Math.PI / 180;
long2 = dolg_B * Math.PI / 180;
cl1 = Math.cos(lat1);
cl2 = Math.cos(lat2);
sl1 = Math.sin(lat1);
sl2 = Math.sin(lat2);
delta = long2 - long1;
cdelta = Math.cos(delta);
sdelta = Math.sin(delta);
y = Math.sqrt(Math.pow(cl2 * sdelta, 2) + Math.pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2));
x = sl1 * sl2 + cl1 * cl2 * cdelta;
ad = Math.atan2(y, x);
dist = ad * 6372795;
return dist;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question