public class geoutil { /** * returns a rectangular range based on latitude and longitude * * @ param lng * Longitude * @param lat * Latitude * @param distance * distance (in meters) * @return [lng1,lat1, lng2,lat2] lower-left corner of the rectangle ( LNG1,LAT1) and upper right Corner (LNG2,LAT2) */ public static double[] getrectangle (double lng, double lat, long distance) { float delta = 111000; if (lng != 0 && lat != 0) { double lng1 = lng - distance / math.abs (Math.Cos (Math.toradians (LAT)) * delta); double lng2 = lng + distance / math.abs (Math.Cos (Math.toradians (LAT)) * delta); double lat1 = lat - (Distance / delta); double lat2 = lat + (distance / delta); return new double[] { lng1, lat1, lng2, lat2 }; } else { // TODO ZHCH equals 0 o'clock calculation formula double lng1 = lng - distance / delta; double lng2 = lng + distance / delta; double lat1 = lat - (Distance / delta); double lat2 = lat + (Distance / delta); return new double[] { lng1, lat1, lng2, lat2 }; } } /** * get the distance between two points m * * @param lat1 1th latitude * @param lng1 1th longitude * @param lat2 2nd latitude * @param lng2 2nd Longitude * @return */ public static Double getdistanceofmeter (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.pow (Math.sin (b / 2), 2)); s =&nbsP;s * earth_radius; s = math.round (S * 10000) / 10; return s; } private Static double rad (double d) { return d * Math.PI / 180.0; } /** * Earth Radius: 6378.137km */ private static double EARTH_RADIUS = 6378.137; }
Java tool class to get the distance between latitude and longitude