Given a lat/lng coordinate, calculate the min and max lat/lng values for a 10 km area

♀尐吖头ヾ 提交于 2019-12-30 03:23:05

问题


Lets say I have a lat lng coordinate and I want to place that at the center of a square that is 10km wide and then get the minimum lat/lng and maximum lat/lng.

Is there an easy way to do this that already exists?


回答1:


If it doesn't need to be exact, it is pretty easy:

For the latitude, 1 km is 0.009 degrees (follows from the original definition of meter). Since your square is 5 km around the center, you just need to add and subtract 0.045 degrees from the center point.

For the longitude, it is slightly more complicated: Divide the above value with the cosine of the latitude.

In code:

lat_min = lat_center - 0.045;
lat_max = lat_center + 0.045;
long_min = long_center - (0.045 / Math.cos(lat_center*Math.PI/180);
long_max = long_center + (0.045 / Math.cos(lat_center*Math.PI/180);

(Math.PI/180 is needed to convert from degrees to radians).

Beware: Does not work around the poles.




回答2:


How is the square oriented? Parallel to the equator? If so, then just do a bearing of 45 deg, 5km * sqrt(2) distance from your lat/lon to get the upper right corner. Similar for the bottom left, use a bearing of 225 deg.

See Destination point given distance and bearing from start point at http://www.movable-type.co.uk/scripts/latlong.html



来源:https://stackoverflow.com/questions/10398481/given-a-lat-lng-coordinate-calculate-the-min-and-max-lat-lng-values-for-a-10-km

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!