2012-03-26 45 views

回答

0

可能有許多方法來完成這件事,這裏是一個選項。

您可以使用distanceTo()方法。如果您想要多於一個距離,只需使用一個循環來重複它,直到您計算出所有位置之間的距離。

+0

你有一些示例代碼? – user1265628 2012-03-26 19:22:01

0

如果您在使用谷歌地圖,你可以使用距離矩陣 https://developers.google.com/maps/documentation/distancematrix/ https://developers.google.com/maps/documentation/javascript/distancematrix

+0

謝謝,但我需要把每個點的距離放在列表中的某個位置......就像四方形的圖像 – user1265628 2012-03-26 19:42:14

+0

如果我正確地理解了你,那麼這就是距離矩陣給你的東西 – 2012-03-26 22:10:42

0

我在這裏爲您提供一些示例代碼距離計算。我在我的項目中這樣做。這裏distanceTo()方法會以double爲單位返回你的距離。

private Location currentLocation, distanceLocation; 
double distance = 0; 

//set your current location 
currentLocation.setLatitude(currentLat); 
currentLocation.setLongitude(currentLong); 

//set your destination location 
distanceLocation = new Location(""); 
distanceLocation.setLatitude(destinatioLat); 
distanceLocation.setLongitude(destinationLong); 

distance = currentLocation.distanceTo(distanceLocation)/1000; 

對於多個位置,您可以使用Array來存儲距離。它根據你的要求對你如何使用它。

希望這會幫助你。

相關問題