点与多个位置之间的距离

时间:2012-03-26 18:15:26

标签: android google-maps location

我正在开发一个应用程序,显示用户与Android上的多个位置之间的距离(如下图中的foursquare),我正在使用eclipse,并想知道如何计算各点之间的距离。谢谢!

图像: http://i.stack.imgur.com/rsWmO.jpg

3 个答案:

答案 0 :(得分:0)

有很多方法可以完成这项工作,这是一个选项。

您可以使用distanceTo()方法。如果您想要多个距离,只需使用循环重复它,直到您计算出手头所有位置之间的距离为止。

答案 1 :(得分:0)

如果您使用的是Google地图,则可以使用距离矩阵 https://developers.google.com/maps/documentation/distancematrix/ https://developers.google.com/maps/documentation/javascript/distancematrix

答案 2 :(得分: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存储距离。根据您的要求,您可以根据自己的需要使用它。

希望这会对你有所帮助。

相关问题