I'm looking to use Android's distanceTo()
method to calculate the distance between the two different object types. I'm using a LatLng
object
as it can be added to a marker
position on Google Maps.
LatLng clontarfFC = new LatLng(53.369615, -6.1859571);
mMap.addMarker(new MarkerOptions().position(clontarfFC).title("Clontarf FC").snippet("St.Annes Park, Clontarf"));
When I add a Location object type into .position() it results in an error as they are incompatible.
I'm declaring a location object
like so that will represent the current location of the user of the app.
Location currentLocation = new Location ("Curent Location");
currentLocation.setLatitude(53.3419322);
currentLocation.setLongitude(-6.2670159);
And I'm attempting to find the distance between the two like so:
final float distance = clontarfFC.distanceTo(currentLocation)/1000;
final String formattedDistance = String.format("%.02f", distance);