我需要在我的java代码中实现harvesine距离.
我在Javascript中找到了这个片段,我需要将其转换为java.
谢谢
dLat = (lat2-lat1).toRad();
dLon = (lng2-lng1).toRad();
a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
d = R * c;
return d;
Run Code Online (Sandbox Code Playgroud)