计算之间的&QUOT的距离; setMyLocationEnabled"和标记在谷歌地图上设置 [英] Calculating the Distance between "setMyLocationEnabled" and a marker set on the google map
问题描述
我试图让Android上的应用程序,它让我看到在谷歌地图上两点之间的距离,距离点是目前我在的位置和其他点正对谷歌地图的标记。
我设法设置我使用 setMyLocationEnabled(真)
地图上的位置,我想那么可以把它比作一个标记我对谷歌地图是
map.addMarker;
您可以使用位置
类的<a href =http://developer.android.com /reference/android/location/Location.html相对=nofollow>此处。
首先设置标记位置:
位置markerLoc =新的位置(标记);
markerLoc.setLatitude(marker.latitude);
markerLoc.setLongitude(marker.longitude);
请参阅这使用来获取当前位置 OnMyLocationChangeListener
和设置您的当前位置:
位置currentLoc =新的位置(当前);
currentLoc.setLatitude(location.latitude);
currentLoc.setLongitude(location.longitude);
然后就可以使用位置
类 distanceTo
方法来获得在这样米的距离:
浮动距离= currentLoc.distanceTo(markerLoc);
I am trying to make an application on Android which allows me to see the distance between two points on google maps, the distance points being The location i am currently at and the other point being a marker on the google maps.
I have managed to set where I am on the map using setMyLocationEnabled(true)
and i want to then be able to compare it to a marker i have on the google map which is
map.addMarker(newMarkerOptions().position(LOCATION_BEIJING).title("Find me here!"));
You can use the Location
class here.
First set the marker location:
Location markerLoc = new Location("Marker");
markerLoc.setLatitude(marker.latitude);
markerLoc.setLongitude(marker.longitude);
See this to get the current Location using OnMyLocationChangeListener
and set your Current Location:
Location currentLoc = new Location("Current");
currentLoc.setLatitude(location.latitude);
currentLoc.setLongitude(location.longitude);
Then you can use the Location
class' distanceTo
method to get the distance in meters like this:
Float distance = currentLoc.distanceTo(markerLoc);
这篇关于计算之间的&QUOT的距离; setMyLocationEnabled&QUOT;和标记在谷歌地图上设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!