Knowledge Base Nr: 00333 tracking.java - http://www.swe-kaiser.de
Downloads:
Java: GWT: zurückgelegte strecke für tracking-daten
public static float GetTrackingLength(String sPoints)
{
double fLen = 0;
String pt[] = sPoints.split("#");
if (pt.length < 2)
return 0;
String val[] = pt[0].split(" ");
if (pt.length < 2)
return 0;
double fLastLat = Double.parseDouble(val[0]);
double fLastLong = Double.parseDouble(val[1]);
for (int n = 0; n < pt.length; n++)
{
String sCoord[] = pt[n].split(" ");
double fLat = Double.parseDouble(sCoord[0]);
double fLong = Double.parseDouble(sCoord[1]);
//mit distance: Entfernung in km
double lat1 = fLastLat;
double lat2 = fLat;
double lon1 = fLastLong;
double lon2 = fLong;
double lat = (lat1 + lat2) / 2 * 0.01745;
double dx = 111.3 * Math.cos(lat) * (lon1 - lon2);
double dy = 111.3 * (lat1 - lat2);
double distance = Math.sqrt(dx * dx + dy * dy);
fLen += Math.abs(distance);
fLastLat = fLat;
fLastLong = fLong;
}
return (float)fLen*1000; //einheit in meter
}