PHP: how to create a geo-fence (bounding block) using distance from a set of codes

How to create Geo-Fence points (bounding box) using lat and lon and at a distance.

I have lat and lon central points. I have geofence.

What would be the logic of creating a geographer around these few points?

Thanks for any help.

+3
source share
2 answers

1 Convert the lat / lon center to the Cartesian (x, y) in units of measure.
Then you do all the geometry, as you learned at school:

2 Create one corner point of the square using the polar coordinate formula

phi = 45 * TO_RADIANS; corner.x = tcenter.x + r * sin(phi); corner.y = tcenter.y + r * cos(phi); 

where r is the length in meter of the half-diagram of the square of the rectangular frame

do the same for other points using phi = (90 * i + 45), i = 0..3

3 convert angles (x / y) back to lat / lon using inverse transform

0
source

If you have a lat / lon point and distance, and you want to find other lat / lon points, this is called the bearing range problem. See Destination Point, Preset Distance and Bearing from the Starting Point on the website http://www.movable-type.co.uk/scripts/latlong.html

If you want the box (fence) to be parallel to the equator, then the bearing for the northeast corner of your box will be 45 degrees (do not forget to translate to radians before using the equations). Then add 90 degrees to get the next corner point until you have all 4 points.

0
source

All Articles