2012-03-26 74 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来存储距离。它根据你的要求对你如何使用它。

希望这会帮助你。