Created
December 3, 2015 14:41
-
-
Save beradrian/0a677af2f149f7f68dbd to your computer and use it in GitHub Desktop.
Distance between two geographical points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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