I have two GPS Coordinates, for example: (44.40239182909422, 8.930511474608954)
and (30.297017883371236, 122.3822021484364)
I would like to know the distance in meters between these two points. I don't know if the first coordinate is greater than the second or not.
I am trying to understand and modify this code example:
private double _distance(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515; // 60 is the number of minutes in a degree; //1.1515 is the number of statute miles in a nautical mile.One nautical mile is the length of one minute of latitude at the equator.
dist = dist * 1.609344;
return (dist);
}
To calculate the 'theta' I added the following code:
double theta = lon1 - lon2;
if(lon2>lon1)
theta = lon2 - lon1;