Skip to content

Instantly share code, notes, and snippets.

@beradrian
Created December 3, 2015 14:41
Show Gist options
  • Save beradrian/0a677af2f149f7f68dbd to your computer and use it in GitHub Desktop.
Save beradrian/0a677af2f149f7f68dbd to your computer and use it in GitHub Desktop.
Distance between two geographical points
package org.bar;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* How far is NY from London ?
*/
public class DistanceTest {
public final static void main(final String[] args) {
final GeodeticCalculator calc = new GeodeticCalculator();
final Point2D london = new Point2D.Double(-0.127512, 51.507222);
final Point2D ny = new Point2D.Double(-73.94, 40.67 );
calc.setStartingGeographicPoint(london);
calc.setDestinationGeographicPoint(ny);
System.out.println("Distance London-NY: " + calc.getOrthodromicDistance()/1000 + " kms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment