我正在使用MapQuest Android API並繪製兩點之間的路線。我想要做的是在路線上找到多個點,例如沿路徑每隔100米指定一次緯度和長度值,並將其存儲在一個數組中。有沒有辦法做到這一點。我希望我的問題清楚明白。路線上的MapQuest點
0
A
回答
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種算法:
- 之間的距離2 [緯度,經度]座標
- 即距離x沿着之間2 [緯度,經度]座標
說起來容易做起來難,這些都是複雜的算法,網上有一些可疑的例子。在我看來,很少有人在解釋數學如何運作方面做得很好,而且我發現的mot是不完整的。
然後我發現這個寶石:http://www.movable-type.co.uk/scripts/latlong.html
我實現我的算法在ActionScript和Java基於由克里斯俯伏這個很好的參考。
鏈接應該提供您需要的一切。對你需要做什麼的解釋,psudocode和javascript中的簡明算法,以及如果這還不夠,可以用來測試你的算法。
相關問題
- 1. 在mapquest上使用mapquest獲取路線積分
- 2. MapQuest行車路線API
- 3. MapQuest ios API無法請求路線
- 4. 優點和缺點mapquest android
- 5. 使用MapQuest API進行超過25站的路線優化
- 6. 使用自定義圖標的Mapquest路線
- 7. 如何將MapBox地圖與Mapquest路線服務一起使用?
- 8. mapkit上的兩點繪圖路線
- 9. 在MapQuest上列入封閉道路的黑名單API
- 10. Mapquest服務路由矩陣響應
- 11. Gmaps路線保存路線,航點
- 12. 翻譯上班路線站點範圍
- 13. 路線通過點
- 14. Ember路線+網點
- 15. 路線中途點
- 16. 使用MapQuest創建從用戶地理位置的路線Directions API
- 17. 如何找出路線上gps點的道路分配?
- 18. GGPLOT2:使線路上的點比線顏色
- 19. Kohana中的點3.2路線
- 20. 點擊MapQuest地圖獲取經緯度
- 21. 查找Mapquest API上的紅綠燈
- 22. MapQuest Infowindow上的新行或換行符
- 23. mapquest:如何解析mapquest json請求
- 24. 在iPhone上的MapKit上找到兩個點之間的路徑/路線
- 25. MapQuest標記點擊監聽器和Infowindow使用Mapquest方向API在android
- 26. MapView:在路線上劃線
- 27. 如何避免點不在路上繪製路線
- 28. 繪製點劃線(....)線索路徑,而不是一個線路(________)
- 29. 包括地圖API V2路線的所有路線點
- 30. Google API(路線) - 創建避開特定點的路線