Delphi 计算两个坐标点之间的距离(高德地图)
参考这个文章,Java写的,改写成Delphi版本:
function MeasuerDistance(const startLongitude,startLatitude,endLongitude,endLatitude:Double):Integer; begin const Earth_RAdius=6378137; var radLatitude1 := startLatitude * PI / 180.0; var radLatitude2 := endLatitude * PI / 180.0; var a := abs(radLatitude1 - radLatitude2); var b := abs(startLongitude * PI / 180.0 - endLongitude * PI / 180.0); var s := 2 * arcsin(sqrt(power(sin(a / 2), 2) + cos(radLatitude1) * cos(radLatitude2) * power(sin(b / 2), 2))); s := s * EARTH_RADIUS; result :=round(round(s * 10000) / 10000); // 返回距离单位是米 end;
向作者表示感谢!