I have to get distance from different markers on the map to the current location of the device and the pick up the shortest one. I have the lat and long for the markers and
How about looping over all markers and checking the distance using Location.distanceBetween? There is no magic involved ;)
List markers;
LatLng currentPosition;
float minDistance = Float.MAX_VALUE;
Marker closest = null;
float[] currentDistance = new float[1];
for (Marker marker : markers) {
LatLng markerPosition = marker.getPosition();
Location.distanceBetween(currentPosition.latitude, currentPosition.longitude, markerPosition.latitude, markerPosition.longitude, currentDistance);
if (minDistance > currentDistance[0]) {
minDistance = currentDistance[0];
closest = marker;
}
}