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:
- Convert center point to km.
- Subtract a half of rectangle's width from x coord.
- Subtract a half of rectangle's height from y coord.
- Add a half of rectangle's width to x coord.
- Add a half of rectangle's height to y coord.
- You have two points now, just convert them to latlng.
精彩评论