2012-02-03 5 views
1

JSP에서 두 위치 간 거리를 계산하는 방법. 나는 두 위치의 좌표를 가지고 있으며, JSP에서이 작업을 수행하는 데 사용할 수있는 함수가 있는지 알고 싶습니다. 안드로이드에서 jsp에서 두 위치 사이의 거리를 계산하십시오

, 난 두 장소 사이의 거리를 계산하기 위해이 같은 기능을 사용하고 있습니다 :

Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, results); 

어떻게 JSP에서이 같은 일을 달성 할 수있다. 거기에 추가 할 jar 파일이 있습니까? 친절하게 도와주세요.

+0

에서 당신이 자바를 계산하고 모르는 방법을 어떻게 알 수 있습니까 포트 JSP에이 솔루션을에 또는 일반 Java SE에서 수행하는 방법을 모르는 경우 –

답변

2

당신은 여기에서 수식을 사용할 수 http://www.koordinaten.com/informations/formula.shtml, 또는 여기 http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe

public class DistanceCalculator { 

private double Radius; 

// R = earth's radius (mean radius = 6,371km) 
// Constructor 
DistanceCalculator(double R) { 
    Radius = R; 
} 

public double CalculationByDistance(GeoPoint StartP, GeoPoint EndP) { 
    double lat1 = StartP.getLatitudeE6()/1E6; 
    double lat2 = EndP.getLatitudeE6()/1E6; 
    double lon1 = StartP.getLongitudeE6()/1E6; 
    double lon2 = EndP.getLongitudeE6()/1E6; 
    double dLat = Math.toRadians(lat2-lat1); 
    double dLon = Math.toRadians(lon2-lon1); 
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
    Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * 
    Math.sin(dLon/2) * Math.sin(dLon/2); 
    double c = 2 * Math.asin(Math.sqrt(a)); 
    return Radius * c; 
} 

}

+0

필자가 제공 한 두 번째 링크의 첫 번째 기능으로 충분하다고 생각합니다. –

관련 문제