java - Java中的GPS计算

标签 java api gps

<分区>

我正在寻找一个 Java API,一个免费的,它提供了计算 GPS 坐标之间距离的基本功能。我需要两点之间的基本 getDistance,一个点周围半径内的兴趣点。
我做了一些研究,一方面发现了一些选择。

一方面有 Apache SIS ( http://incubator.apache.org/sis/index.html ),但这仍在开发中,可能会有所改变。 另一方面是 GeoTools ( http://docs.geotools.org/ ),但这对我的需求来说相当复杂。

还有其他易于使用且更简单的 API 吗?

另一种选择是自己简单地实现所有这些,我已经看到了一些自己实现的例子,但他们都有这样的评论:“这实际上行不通,它提供了一个距离离开 100 米”。这样的实现有多可靠?

最佳答案

使用 GeoTools 和 Maven,应该不会太难。 Maven 会处理依赖关系。幸运的是,您不需要整个 Geotools 套件来进行“ headless ”计算。

我希望这就是您要找的。

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>

代码:

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");
  }

}

关于java - Java中的GPS计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15927664/

相关文章:

javascript - 错误: Connection lost: The server closed the connection. mysql Node

c# - 如何获取 Web API IHttpActionResult 响应并序列化 c#

ios - 如何将带有 GPS 位置的 exif 数据写入 iPhone 上的 uiimage?

android - GPS 状态和 TurnOnOff

java - 静态初始化程序和静态同步方法锁定问题

java - 扩展类构造函数被调用两次

api - 如何使用Gaana API播放歌曲?

java - 如何使 jtable 单元格监听另一个单元格的更改

java - 无法向玩家展示独立的记分牌

java - Android : why does native_start fails in startNavigating() on Android 2. 3.1 模拟器?