The latitude and longitude of a given two point. Calculates the distance between two points. Note that latitude and longitude must be filled in order.
1. Use the tools in Android to get the units in meters
Float[] Results=new float[1]; Location.distancebetween (latitude,longitude,double.parsedouble (LAT), double.parsedouble (LNG), results); LOG.I ("Distance", results[0]+ "");
2. Obtained by means of calculation, the unit is kilometer
Private static final Double Earth_radius = 6378.137; private static Double rad (double D) { return d * math.pi/180.0; } /** * Calculates the distance between two points according to the latitude and longitude coordinates (double value) between two points, * * @param lat1 * @param lng1 * @param lat2 * @param lng2< c10/>* @return Distance: kilometers per km /public static double distanceoftwopoints (double lat1,double lng1, double Lat2,double lng2) { double radLat1 = rad (LAT1); Double radLat2 = rad (LAT2); Double A = RADLAT1-RADLAT2; Double b = rad (lng1)-Rad (lng2); Double s = 2 * Math.asin (MATH.SQRT (Math.pow (Math.sin (A/2), 2) + math.cos (RADLAT1) * Math.Cos (RADLAT2) * MATH.P Ow (Math.sin (B/2), 2))); s = S * earth_radius; s = Math.Round (S * 10000)/10000; LOG.I ("Distance", s+ ""); return s; }
Calculate distance for the given coordinates of Android