2013-04-09 1 views

답변

2

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; 
} 
+1

또는 https://developer.android.com/reference/android/ location/Location.html # distanceTo % 28android.location.Location % 29 –

+0

@ankitmakwana WebView에서 경도 및 위도를 지정하는 방법을 알려주시겠습니까? –

+0

@PratikButani 당신은 GeoPoint를 사용하여 디스플레이 할 수 있습니다 –

0

만 몇 줄 :

Location l1=new Location("One"); 
l1.setLatitude(location.getLatitude()); 
l1.setLongitude(location.getLongitude()); 

Location l2=new Location("Two"); 
l2.setLatitude(Double.parseDouble(frnd_lat)); 
l2.setLongitude(Double.parseDouble(frnd_longi)); 

float distance_bw_one_and_two=l1.distanceTo(l2);