开发者

Google Maps API Rectangle

I'm building a web app that makes use of the Google Maps API and have run across a small math problem.

I have a ce开发者_运维知识库nter point in lat/lng and an area in kilometres. How would I calculate the NE and SW lat/lng points for a bounding box? Thanks.


Consider using methods of Projection class http://code.google.com/apis/maps/documentation/javascript/reference.html#Projection to convert values from latang format to km and back.

I can suggest the following algo:

  1. Convert center point to km.
  2. Subtract a half of rectangle's width from x coord.
  3. Subtract a half of rectangle's height from y coord.
  4. Add a half of rectangle's width to x coord.
  5. Add a half of rectangle's height to y coord.
  6. You have two points now, just convert them to latlng.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜