我正在尝试在Android上制作一个应用程序,它允许我查看谷歌地图上两点之间的距离,距离点是我当前所在的位置,另一个点是谷歌地图上的标记。
我已经成功使用setMyLocationEnabled(true)
设置了我在 map 上的位置,然后我希望能够将它与我在谷歌地图上的标记进行比较
map.addMarker(newMarkerOptions().position(LOCATION_BEIJING).title("Find me here!"));
最佳答案
您可以使用Location
类here 。
首先设置标记位置:
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);
关于javascript - 计算 "setMyLocationEnabled"与谷歌地图上设置的标记之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30419112/