问题
How would i create the points of a Geo-Fence(bounding box) using lat and lon and a distance.
I have the lat and lon of the center point I have the geofence distance.
What would the logic be to create the geo-fence around these multiple points?
thanks for any help.
回答1:
1 Convert center lat / lon to cartesian (x,y) in units meter.
Then you do all geometry as you have learned in school:
2 Create one corner point of the square, using polar coordinates 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 diagonal of your bounding box square
do the same for the other points by using phi =(90*i + 45), i= 0..3
3 transform corners (x/y) back to lat/lon using the inverse transformation
回答2:
If you have a lat/lon point and a distance and you want to find other lat/lon points, this is called a bearing-range problem. See the section Destination point given distance and bearing from start point at the website http://www.movable-type.co.uk/scripts/latlong.html
If you want the box (fence) parallel to the equator, then a bearing for the north-east corner of your box will be 45 degrees (don't forget to convert to radians before using the equations). Then add 90 degrees to get the next corner point until you have done all 4 points.
来源:https://stackoverflow.com/questions/14519322/php-how-to-create-a-geo-fencebounding-box-using-the-distance-from-a-set-of-co