Floating point offset and setZoom in Google Maps
Google Maps documentation says .zoom and setZoom () expect numbers. Everything seems to indicate that these numbers are integers. However, today I gave the last one a floating point value and it worked ... sort of.
var MAP;
function initialize() {
MAP = new google.maps.Map(document.getElementById('map-canvas'),
{
zoom : 5,
center : new google.maps.LatLng(-25.610111, 134.354806),
mapTypeId : google.maps.MapTypeId.ROADMAP
});
}
Using the above code, I was able to access the debugger of the MAP object.
Now in the case of mainland Australia, if I have a zoom of 4, I get a slice of Southeast Asia, all of Papua New Guinea and New Zealand and, in the center, the Great Southern Land. If I have a zoom of 5 I get the mainland, but without Tasmania it is definitely a "bad thing". The optimal scaling found with MAP.setZoom () interactively is 4.3. This is great, except that nothing else works with this magnification. When I try to draw polygons or heat map, Maps cause errors like
GET https://khms0.google.com/kh?v=178&hl=en-US&x=0&y=0&z=0.2999999999999998&token=77820 404 (OK)
I believe the "z" value above means 404 - khms0.google.com does not expect a "z" floating point value.
So how do I get a more suitable zoomed home with polygons, markers, heat maps, KML layers, and what do you have?
By the way, I tried to use fitBounds () but didn't change anything about the viewport's visible content other than wrapping the map around the new center.
var se = new google.maps.LatLng(-44.999315, 156.971343); // Tasman Sea
var nw = new google.maps.LatLng(-9.063496, 106.346343); // Indian Ocean
var bs = new google.maps.LatLngBounds(nw,se);
MAP.fitBounds(bs);
source to share
The zoom level should be integer (at least for the time being). This has been documented before, but I don't see it being specified anywhere.
If an integer zoom level doesn't work for you, either resize <div>
to display the map, or create your own tiles that are at different scales.
source to share