Following two line calculate the lat and lng
double geoLat = location.getLatitude(); // 37.422006
double geoLng = location.getLongitude(); // -122.084095
In a loop i calculate the distance array between geo points. latitude[i] and longitude[i] comes as json response from google map api
distance[i]=GetLatAndLng.gps2m(geoLat, geoLng,latitude[i] ,longitude[i]);
This is gps2m method.
public static double gps2m(double lat1, double lng1, double lat2, double lng2) {
double l1 = Math.toRadians(lat1);
double l2 = Math.toRadians(lat2);
double g1 = Math.toRadians(lng1);
double g2 = Math.toRadians(lng2);
double dist = Math.acos(Math.sin(l1) * Math.sin(l2) + Math.cos(l1) * Math.cos(l2) * Math.cos(g1 - g2));
if(dist < 0) {
dist = dist + Math.PI;
}
return Math.round(dist * 6378100);//in meters
}
}
In the distance array i m getting value like 1.1967617E7 I want distance in meters
What is going wrong and how to get distance in meters.
Help!!