---
title: 'Latitude/Longitude distance in Java'
url: 'https://tutego.de/blog/javainsel/2009/09/latitudelongitude-distance-in-java'
markdown: 'https://tutego.de/blog/javainsel/2009/09/latitudelongitude-distance-in-java.md'
date: '2009-09-02'
description: '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…'
taxonomy:
  category:
    - Allgemein
---

# Latitude/Longitude distance in Java

![Illustration einer tropischen Insel mit Palmen und einem hohen Berg](https://tutego.de/blog/javainsel/user/themes/tutego/images/insel-cover.jpg)# Java Blog für Programmierer

[Java Blog für Programmierer](https://tutego.de/blog/javainsel/)

## Latitude/Longitude distance in Java

02.09.2009 · [Christian Ullenboom](https://tutego.de/blog/javainsel/author/admin/)

 ```java
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));  //      }}
```

Kategorien: [Allgemein](https://tutego.de/blog/javainsel/category/allgemein/)

## 1 Kommentare

**Thema der Woche: Programmieren mit einem bisschen Geo** · [26.04.2010 17:04](#comment-119)

\\\[...\\\] und parametrisieren Konstruktor. Die Klasse Location soll die Abstands-Utility-Funktionen aus http://www.tutego.de/blog/javainsel/2009/09/latitudelongitude-distance-in-java/ \\\[...\\\]

Die bisherigen Kommentare wurden aus WordPress übernommen. Neue Kommentare sind derzeit geschlossen.

[← Alle Beiträge](https://tutego.de/blog/javainsel/)

---

## Navigation

- Next: [Thema der Woche: Programmieren mit einem bisschen Geo](https://tutego.de/blog/javainsel/2009/09/thema-der-woche-programmieren-mit-einem-bisschen-geo.md)
