I have calculated the distance between two places by using Latitude and longitude.Some times it showing wrong distance.I need to calculate exact distance in miles. Could you please help. what should i make changes in my code.
Here is my Code.
lat2 and lng2 are the current location geo points I have taken these by NETWORK PROVIDER/GPS.
lat1 and lng2 are the destination geo poin
double earthRadius = 3958.75;//earthRadius in miles
// double earthRadius = 6371;
double dLat = Math.toRadians(lat1-lat2);
double dLng = Math.toRadians(lng1-lng2);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat2)) * Math.cos(Math.toRadians(lat1)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;//distance in miles
Thanks you..
Try like this.