Baidu maps Android SDK API inside, there is no immediate way to get the distance between two coordinate points, but, in the JSAPI, there is a direct way to calculate the distance.
class Point:pass def max (A, b):ifA>B:returnareturnb def min (a,c):ifA>C:returnCreturna def LW (A, B, c): # b! = N && (a =Math.max (A, b)); # c! = N && (a =Math.min (A, c)); A=Max (A, b) a=min (a,c)returna def ew (A, B, c): whileA >c:a-= C-b whileA <b:a+ = C-breturnA def oi (a):returnMath.PI * a/180def Td (A, B, C, D):return6370996.81 * Math.acos (Math.sin (c) * Math.sin (d) + Math.Cos (c) * Math.Cos (d) * Math.Cos (B-a) def Wv (A, b):ifNot A or not B:return0; A.LNG= EW (A.LNG,-180, 180); A.lat= LW (A.lat,-74, 74); B.LNG= EW (B.LNG,-180, 180); B.lat= LW (B.lat,-74, 74); returnTd (Oi (a.lng), Oi (b.lng), Oi (A.lat), Oi (B.lat)) def getdistance (A, B): C=Wv (A, b); returnC
So, based on the above method, we have implemented the method of calculating distances in the Java language as follows:
Public Static DoubleGetdistance (DoubleLat_a,DoubleLng_a,DoubleLat_b,DoubleLng_b) { DoublePK = 180/3.14169; DoubleA1 = lat_a/PK; DoubleA2 = lng_a/PK; DoubleB1 = lat_b/PK; DoubleB2 = Lng_b/PK; DoubleT1 = Math.Cos (A1) * MATH.COS (A2) * MATH.COS (B1) *Math.Cos (B2); DoubleT2 = Math.Cos (A1) * Math.sin (A2) * MATH.COS (B1) *Math.sin (B2); DoubleT3 = Math.sin (A1) *Math.sin (B1); Doublett = math.acos (t1 + t2 +T3); return6371000 *tt; }
Reference:
http://blog.csdn.net/mad1989/article/details/9933089
http://blog.csdn.net/pleasurelong/article/details/26855049
Baidu Map API calculates distances based on two coordinate points