【问题标题】:Calculating the Distance between "setMyLocationEnabled" and a marker set on the google map计算“setMyLocationEnabled”与谷歌地图上设置的标记之间的距离
【发布时间】:2015-05-24 01:04:44
【问题描述】:

我正在尝试在 Android 上制作一个应用程序,它允许我查看谷歌地图上两点之间的距离,距离点是我当前所在的位置,另一点是谷歌地图上的标记。

我已经设法使用setMyLocationEnabled(true) 设置我在地图上的位置,然后我希望能够将它与我在谷歌地图上的标记进行比较

map.addMarker(newMarkerOptions().position(LOCATION_BEIJING).title("Find me here!"));

【问题讨论】:

  • 您是否像标签建议的那样使用 javascript?

标签: javascript android google-maps google-maps-api-3


【解决方案1】:

您可以使用Locationhere。 首先设置标记位置:

Location markerLoc = new Location("Marker");
markerLoc.setLatitude(marker.latitude);
markerLoc.setLongitude(marker.longitude);

查看this 以使用OnMyLocationChangeListener 获取当前位置并设置您的当前位置:

Location currentLoc = new Location("Current");
currentLoc.setLatitude(location.latitude);
currentLoc.setLongitude(location.longitude);

然后您可以使用Location 类的distanceTo 方法来获取以米为单位的距离,如下所示:

Float distance = currentLoc.distanceTo(markerLoc);

【讨论】:

    猜你喜欢
    • 2014-08-29
    • 2016-08-28
    • 1970-01-01
    • 2011-09-21
    • 2023-03-23
    • 2010-12-02
    • 1970-01-01
    • 2013-09-30
    相关资源
    最近更新 更多