Hi, I am working on an enhancement to the map accessible at http://travellr.com/map
The idea is to be able to load the map on a country, and have the map zoomed to appropriately fit the country. For all countries I have co- ordinates and bounding boxes already. The problem is that when using Map.fitBounds(), the zoom level sometimes isn't quite right - for loading on countries I would like to limit zoom within a min / max, and places like Russia and Canada break out of that. After using Map.fitBounds(), I could then check the zoom level once the zoom_changed event fires, and if required update it, but that seems quite a clunky multi step process. Ideally I would like to be able to calculate the zoom level prior to instantiating the map. However the API v3 does not seem to provide a way to do this. I have read some solutions akin to: // mnode = the map node // bounds = a bounding box function best_zoom(bounds, mnode) { var width = mnode.offsetWidth; var height = mnode.offsetHeight; var dlat = Math.abs(bounds.maxY - bounds.minY); var dlon = Math.abs(bounds.maxX - bounds.minX); // Center latitude in radians var clat = Math.PI*(bounds.minY + bounds.maxY)/360.; var C = 0.0000107288; var z0 = Math.ceil(Math.log(dlat/(C*height))/Math.LN2); var z1 = Math.ceil(Math.log(dlon/(C*width*Math.cos(clat)))/ Math.LN2); return (z1 > z0) ? z1 : z0; } However this does not seem to provide the correct zoom levels (they increase as dlat or dlon increase, shouldn't they go down?) - Please tell me if I am missing something here? Also, where does the constant C come from? Thanks for your help. - Jai -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api...@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.