我正在寻找一个免费的Java API,它提供了计算GPS坐标之间距离的基本功能.我需要两点之间的基本getDistance,即一个点周围半径的兴趣点.
我做了一些研究,一方面发现了一些选择.
一方面有Apache SIS(http://incubator.apache.org/sis/index.html),但这仍在开发中,可能会改变一些.另一方面是GeoTools(http://docs.geotools.org/),但这对我的需求来说相当复杂.
还有其他易于使用且更简单的API吗?
另一种选择是简单地自己实现所有这些,我已经看到了一些自己的实现的例子,但是它们都有一些类似的评论:"这不是真正的工作,它提供的距离是100米".这样的实施有多可靠?
使用GeoTools和Maven,它应该不会太难.Maven将负责依赖.幸运的是,您不需要整个Geotools套件来进行"无头"计算.
我希望这就是你要找的东西.
pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bar</groupId>
<artifactId>geo</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repository</name>
<url>http://repo.opengeo.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>9.0</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
代码:
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");
}
}
Run Code Online (Sandbox Code Playgroud)