Skip to content Skip to sidebar Skip to footer

Calculating The Distance Between "setMyLocationEnabled" And A Marker Set On The Google Map

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 th

Solution 1:

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);

Post a Comment for "Calculating The Distance Between "setMyLocationEnabled" And A Marker Set On The Google Map"