0

我正在使用MapQuest Android API并绘制两点之间的路线。我想要做的是在路线上找到多个点,例如沿路径每隔100米指定一次纬度和长度值,并将其存储在一个数组中。有没有办法做到这一点。我希望我的问题清楚明白。路线上的MapQuest点

回答

0

如果您尝试减少路径中的点数,但仍然保留精确的路径表示,最好的方法是使用线简化算法。

公共线,简化算法是道格拉斯 - 普克,并有道格拉斯 - 普克的,你可以使用谷歌MyTracks项目的实施,在Apache许可V2.0: https://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/util/LocationUtils.java#78

下面的代码,以防万一链接断裂:

/** 
* Decimates the given locations for a given zoom level. This uses a 
* Douglas-Peucker decimation algorithm. 
* 
* @param tolerance in meters 
* @param locations input 
* @param decimated output 
*/ 
private static void decimate(double tolerance, ArrayList<Location> locations, ArrayList<Location> decimated) { 
    final int n = locations.size(); 
    if (n < 1) { 
    return; 
    } 
    int idx; 
    int maxIdx = 0; 
    Stack<int[]> stack = new Stack<int[]>(); 
    double[] dists = new double[n]; 
    dists[0] = 1; 
    dists[n - 1] = 1; 
    double maxDist; 
    double dist = 0.0; 
    int[] current; 

    if (n > 2) { 
    int[] stackVal = new int[] { 0, (n - 1) }; 
    stack.push(stackVal); 
    while (stack.size() > 0) { 
     current = stack.pop(); 
     maxDist = 0; 
     for (idx = current[0] + 1; idx < current[1]; ++idx) { 
     dist = LocationUtils.distance(
      locations.get(idx), locations.get(current[0]), locations.get(current[1])); 
     if (dist > maxDist) { 
      maxDist = dist; 
      maxIdx = idx; 
     } 
     } 
     if (maxDist > tolerance) { 
     dists[maxIdx] = maxDist; 
     int[] stackValCurMax = { current[0], maxIdx }; 
     stack.push(stackValCurMax); 
     int[] stackValMaxCur = { maxIdx, current[1] }; 
     stack.push(stackValMaxCur); 
     } 
    } 
    } 

    int i = 0; 
    idx = 0; 
    decimated.clear(); 
    for (Location l : locations) { 
    if (dists[idx] != 0) { 
     decimated.add(l); 
     i++; 
    } 
    idx++; 
    } 
    Log.d(Constants.TAG, "Decimating " + n + " points to " + i + " w/ tolerance = " + tolerance); 
} 
0

我在Java和Actionscript中做了类似的事情。首先,如果你还没有意识到,你所拥有的路线中的每一条腿都是直线。路线越平直,你的腿就越少。

要确定沿着路线等距离的点 - 或者在我的情况下沿着路线的行驶时间 - 只需循环计算每条腿末端的累积距离[lat,long]坐标集。

使用此信息,您可以轻松修改您的循环以检查沿着腿部发生距离点(或多个点)的位置。记住每条腿是一条直线。如果是这样,它足够简单,可以识别沿着你正在寻找的腿部的距离,并从中计算远处的腿部。

为此需要2种算法:

  1. 之间的距离2 [纬度,经度]坐标
  2. 即距离x沿着之间2 [纬度,经度]坐标
一行中的点

说起来容易做起来难,这些都是复杂的算法,网上有一些可疑的例子。在我看来,很少有人在解释数学如何运作方面做得很好,而且我发现的mot是不完整的。

然后我发现这个宝石:http://www.movable-type.co.uk/scripts/latlong.html

我实现我的算法在ActionScript和Java基于由克里斯俯伏这个很好的参考。

链接应该提供您需要的一切。对你需要做什么的解释,psudocode和javascript中的简明算法,以及如果这还不够,可以用来测试你的算法。