Google Maps Bounds and Zoom
November 19, 2010 3:58 AM   Subscribe

Google maps KML zoom and centering: I need to inventory a variety of polygons and points on a single map, some from a database and some from KML files. Can you help point me in the right direction?

I have a home-grown CMS with some limited Google map functionality. I now allow folks to upload KML files, and display them in their map. They can also add points manually via a CMS interface. All this works well as far as displaying on the map. However, I lack the requisite knowledge on inventorying the entire set of items being displayed and setting the zoom and center so that everything is visible at the initial rendering.

Before I added the KML file linking ability, to find the zoom and center when outputting the map I added each point to the "bounds" array, and then:


And I know that if all I am displaying is a single KML file, I could simply use:


What I think I need to do to work with multiple KML files and individually added markers: parse the coords in the KML file(s) and add every one to the "bounds" array. Problem is, I'm not sure how best to do that.

What would you parse the KML, if that's what I need to do?
posted by maxwelton to Computers & Internet (2 answers total) 1 user marked this as a favorite
This question might find a lot more audience at
posted by hobu at 6:42 AM on November 19, 2010

Does your backend database support GEOS spatial functions? If so, you can find the centre with something like Centroid(Envelope(Union( ... all your stuff ... ).
posted by scruss at 6:51 AM on November 19, 2010

« Older Im looking for some advice on the best way to...   |   Find a sticker, you'll feel better! Newer »
This thread is closed to new comments.