2012-01-19 3 views

답변

2

public class getDistanceList 
{ 
/** 
* 
* @param lat1 Latitude of the First Location 
* @param lng1 Logitude of the First Location 
* @param lat2 Latitude of the Second Location 
* @param lng2 Longitude of the Second Location 
* @return distance between two lat-lon in float format 
*/ 

public static float distFrom (float lat1, float lng1, float lat2, float 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; 

    int meterConversion = 1609; 

    return new Float(dist * meterConversion).floatValue(); 
} 
+0

만약 내가 30의 위도와 30의 경도를 가지고 있다면 가장 가까운 것을 찾는 방법은 – Vamshi

+0

입니다. 그런 다음 30 번에 대해 for 루프를 실행해야합니다. 첫 번째 lat-long은 동일 할 것이고 다음 lat-long은 30 가지 lal이 될 것입니다. 이제 거리를 찾고 원하는 답을 얻으십시오. – Lucifer

+0

아니요, 위도가 1이 아닌 현재 위치에서 거리가 필요합니다. – Vamshi

관련 문제