Android: how to get the distance between two geo-coordinates?

I used this request URL

http://maps.google.com/maps?q=from+A+to+B&output=kml

which is indicated in the answer to this question . But after I tried, it does not work with coordinates. It works with tho address names. I think I could use google geocoding to get the addresses first. But I wonder if there is another way to get the walking distance between the two coordinates?

+5
source share
1 answer

My new answer :)

Use the Google Directions API .

http://maps.google.com/maps/api/directions/<json|xml>?<params> origin destination. , . , , . , . :

[...] () - /, [...]

, . JSON. ( , XML).

: URL: http://maps.google.com/maps/api/directions/json?origin=49.75332,6.50322&destination=49.71482,6.49944&mode=walking&sensor=false

. Google, .

A , () (Haversine) (python pl/sql)

python:

from math import sin, cos, radians, sqrt, atan2

    def lldistance(a, b):
   """
   Calculates the distance between two GPS points (decimal)
   @param a: 2-tuple of point A
   @param b: 2-tuple of point B
   @return: distance in m
   """
   r = 6367442.5             # average earth radius in m
   dLat = radians(a[0]-b[0])
   dLon = radians(a[1]-b[1])
   x = sin(dLat/2) ** 2 + \
       cos(radians(a[0])) * cos(radians(b[0])) *\
       sin(dLon/2) ** 2
   #original# y = 2 * atan2(sqrt(x), sqrt(1-x))
   y = 2 * asin(sqrt(x))
   d = r * y

   return d

Java .

+5