Pra*_*ani 5 android geolocation android-location android-mapview
我是android开发新手,我想创建一个应用程序,比如在我当前位置和选定位置之间给我MapView的距离.
请给我一些建议.
使用 android 获取当前位置和选定地点之间的距离。
public static double distFrom(
double lat1, double lng1, double lat2, double lng2)
{
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
return dist;
}
Run Code Online (Sandbox Code Playgroud)