I have the top left lat/lon and bottom right lat/lon for my bounding box.
How do I determine whether a given lat/lon is within that bounding box?
Here is the bounding box I'm working with: Top left lat: 51.780586 Top left lon: -0.727844 Bottom right lat: 51.260196 Bottom right lon: 0.590515
My point is: Lat: 51.508039 Lon: -0.128069
I'm going round circles with this at the moment, any help would be appreciated.
From your description the top left and bottom right corners are generally referred to as the Northwest (NW) and Southeast (SE) corners of a bounding box. Determining if a point is inside is simply checking if the latitude and longitude are within the outer latitude and longitude of the bounding box. Below is psuedo code (where NW.Lat is the latitude of the NW corner, etc).
If ( ( Lat <= NW.Lat && Lat >= SE.Lat ) &&
( Lon >= NW.Lon && Lon <= SE.Lon ) )
{
// The point is in the box
}
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