Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating bounding box a certain distance away from a lat/long coordinate in Java

Given a coordinate (lat, long), I am trying to calculate a square bounding box that is a given distance (e.g. 50km) away from the coordinate. So as input I have lat, long and distance and as output I would like two coordinates; one being the south-west (bottom-left) corner and one being the north-east (top-right) corner. I have seen a couple of answers on here that try to address this question in Python, but I am looking for a Java implementation in particular.

Just to be clear, I intend on using the algorithm on Earth only and so I don't need to accommodate a variable radius.

It doesn't have to be hugely accurate (+/-20% is fine) and it'll only be used to calculate bounding boxes over small distances (no more than 150km). So I'm happy to sacrifice some accuracy for an efficient algorithm. Any help is much appreciated.

Edit: I should have been clearer, I really am after a square, not a circle. I understand that the distance between the center of a square and various points along the square's perimeter is not a constant value like it is with a circle. I guess what I mean is a square where if you draw a line from the center to any one of the four points on the perimeter that results in a line perpendicular to a side of the perimeter, then those 4 lines have the same length.

like image 785
Bryce Thomas Avatar asked Nov 06 '09 17:11

Bryce Thomas


People also ask

How is bounding box calculated?

A degenerate bounding box is one that has one or more sides of 0 length. Assume your data is in a two-dimensional space and you decide to use a simple length times width calculation to compute the size of a bounding box. If the width of the bounding box subsequently shrinks to 0, then the size of the bounding box is 0.

How do you find the latitude and longitude of a bounding box?

It is very simple just go to panoramio website and then open World Map from panoramio website. Then go to specified location whichs latitude and longitude required. Then you found latitude and longitude in address bar for example in this address.


1 Answers

I wrote an article about finding the bounding coordinates:

http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates

The article explains the formulae and also provides a Java implementation. (It also shows why IronMan's formula for the min/max longitude is inaccurate.)

like image 191
Jan Philip Matuschek Avatar answered Oct 21 '22 19:10

Jan Philip Matuschek