java - Get distance between two different latitude and longitude in android? -


i have used locationa.distanceto(locationb); , have copy pasted method written haversine formula.

the actual distance between 2 geopoints 25m result of 6894.52192658389 using above methods.

followed this:creating method using haversine formula, android v2 , find distance between 2 points on map using google map api v2

checked distance using free tool http://www.onlineconversion.com/map_greatcircle_distance.htm

you can try code below :

public static float distfrom(float lat1, float lng1, float lat2, float lng2) {     double earthradius = 6371000; //meters     double dlat = math.toradians(lat2-lat1);     double dlng = math.toradians(lng2-lng1);     double = math.sin(dlat/2) * math.sin(dlat/2) +                math.cos(math.toradians(lat1)) * math.cos(math.toradians(lat2)) *                math.sin(dlng/2) * math.sin(dlng/2);     double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));     float dist = (float) (earthradius * c);      return dist;     } 

it gives result in meters, can convert required unit.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -