.
Veröffentlicht von Christian Ullenboom
am Mittwoch, September 02, 2009. 
public class LongLatUtils
{
/**
* Calculates the great circle distance between two points on the Earth. Uses the Haversine Formula.
*
* @param latitude1 Latitude of first location in decimal degrees.
* @param longitude1 Longitude of first location in decimal degrees.
* @param latitude2 Latitude of second location in decimal degrees.
* @param longitude2 Longitude of second location in decimal degrees.
* @return Distance in meter.
*/
public static double distance( double latitude1, double longitude1, double latitude2, double longitude2 )
{
double latitudeSin = Math.sin( Math.toRadians(latitude2 - latitude1) / 2 );
double longitudeSin = Math.sin( Math.toRadians(longitude2 - longitude1) / 2 );
double a = latitudeSin * latitudeSin
+ Math.cos( Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2) ) * longitudeSin * longitudeSin;
double c = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1 - a) );
return 6378137 * c;
}
/**
* Converts latitude and longitude from degrees, minutes, and seconds in decimal degrees.
*
* @param degrees
* @param minutes
* @param seconds
* @return Latitude and longitude in decimal degrees.
*/
public static double convertDegreesMinutesSecondsToDecimalDegrees( int degrees, int minutes, int seconds )
{
return degrees + minutes/60. + seconds/3600.;
}
// public static void main(String[] args)
// {
// System.out.println( convertDegreesMinutesSecondsToDecimalDegrees(38, 53, 23 ));
// System.out.println( distance(38.898556, -77.037852, 38.897147, -77.043934));
// }
}
Ist da bei den @Parameter etwa was vertauscht worden?
Quelltextbeispiele sind ja prinzipiell super, aber ohne entsprechende Formatierung - wie in diesem Blog - sind ziemlich schwierig zu lesen.
Ein Plugin wie etwa SyntaxHighlighter (http://alexgorbatchev.com/wiki/SyntaxHighlighter) wäre wünschenswert.
MfG,
Michael
Das Rechnen mit Koordinaten erfordert oft viel Lineare Algebra und schnelle trigonometrische Funktionen. Java ist da aber leider dafür nicht besonder gut ausgestattet und weisst Performanceprobleme auf. Daher rechnen viele Leute ihre Koordinaten gleich in der Datenbank um.
Daher wollte ich hier mal kurz jBLAS (http://www.jblas.org) vorstellen, das im Prinzip ein Wrapper um BLAS/ATLAS und LAPACK ist und damit brutal schnell ist und trotz nativer fortran libs per fat jar out-of-the-box laeuft. Ich habe es an der Uni mit einem Freund zusammen entwickelt und wir setzen es derzeit für unsere Forschung ein. Ich habe hier ein kleines jBLAS Beispiel bereitgestellt in dem man die Syntax einmal sehen kann.