Find distance between two points on map using Google Map API V2

In Google Map API V2 You have LatLng objects so you can’t use distanceTo (yet).

You can then use the following code considering oldPosition and newPosition are LatLng objects :

// The computed distance is stored in results[0].
//If results has length 2 or greater, the initial bearing is stored in results[1].
//If results has length 3 or greater, the final bearing is stored in results[2].
float[] results = new float[1];
Location.distanceBetween(oldPosition.latitude, oldPosition.longitude,
                newPosition.latitude, newPosition.longitude, results);

For more informations about the Location class see this link

Leave a Comment