【问题标题】:How to find the distance between two location on map i如何在地图上找到两个位置之间的距离
【发布时间】:2017-04-13 08:53:51
【问题描述】:

如何在android ecillipse项目&php上求两个位置的距离。该项目基于在线良好的运输系统。需要找出承运人的票价,因此需要找到源和目的地之间的距离。实施Harversine公式以找到该区域内最短的车辆

【问题讨论】:

  • Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, 结果);

标签: android android-location google-developers-console


【解决方案1】:
float[] results = new float[1];
Location.distanceBetween(source.latitude, source.longitude,
                    destination.latitude, destination.longitude,
                    results);

计算两个之间的近似距离(以米为单位) 位置,以及可选的初始和最终轴承 它们之间的最短路径。距离和方位角是使用 WGS84 椭球体。计算出的距离存储在 results[0] 中。如果结果有长度 2 或更大,初始方位存储在结果[1] 中。如果结果有 长度为 3 或更大,最终方位存储在 results[2] 中。

  @param startLatitude the starting latitude
  @param startLongitude the starting longitude
  @param endLatitude the ending latitude
  @param endLongitude the ending longitude
  @param results an array of floats to hold the results

  @throws IllegalArgumentException if results is null or has length < 1

【讨论】:

    【解决方案2】:

    试试这个代码

    double _distance = Location.distanceBetween(
                     _firstLatitude,
                     _firstLongitude,
                     _secondLatitude,
                     _secondLongitude,
                     _results);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多