I have a geo latitude and longitude (ex: 39.6199,-79.9535). How can I build a bounding box in Java around the point with 1km of radius?
The distance between two longitude lines changes according to the latitude line you're on. It can be computed as:
3960 * 2 * pi /360 * cosine(latitude)
in miles
The distance between two latitude lines is constant everywhere: 69
miles.
So, in order to draw a square of 1x1 miles around a geographical location you should find the two latitude lines parallel to the latitude of the point with distance 0.5 mile along south and north. Then find two parallel longitude lines with 0.5 miles distance along west and east.
For example, 0.5 mile means 0.5/69 latitude difference. If the latitude of the given point is 39.6199 then the latitudes of upper and lower sides of the square have latitude values: 36.6199+(0.5/69)
and 36.6199-(0.5/69)
respectively.
double latitude = location.getLatitude();
double longitude = location.getLongitude();
// 6378000 Size of the Earth (in meters)
double longitudeD = (Math.asin(1000 / (6378000 * Math.cos(Math.PI*latitude/180))))*180/Math.PI;
double latitudeD = (Math.asin((double)1000 / (double)6378000))*180/Math.PI;
double latitudeMax = latitude+(latitudeD);
double latitudeMin = latitude-(latitudeD);
double longitudeMax = longitude+(longitudeD);
double longitudeMin = longitude-(longitudeD);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With