I recently came across a similar issue. The basic issue was that the containing <DIV>
for the map
was itself being initialized during the map initialization. My problem was compounded because map.zoomTo()
doesn't work during map initialization anyway (since 2.5.3 map loading is always asynchronous)
The crux of the issue was that I was trying to use zoomTo()
on a 0x0 pixel map since the <DIV>
wasn't displayed yet - hence I ended up with a zoomLevel
zero map.
The solution is to add listeners to the map as shown:
map.addListener("displayready", function () {
if(bbox){map.zoomTo(bbox, false);}
});
map.addListener("resize", function () {
if(bbox){map.zoomTo(bbox, false);}
});
And set up the bbox
parameter as each coordinate
is received as shown:
function onCoordinateReceived(coordinate){
if(bbox){
bbox = nokia.maps.geo.BoundingBox.coverAll([
bbox.topLeft, bbox.bottomRight, coordinate]);
} else {
bbox = nokia.maps.geo.BoundingBox.coverAll([coordinate]);
}
map.zoomTo(bbox, false);
}
So that:
- If the
map
is already intialized and displayed thezoomTo()
in theonCoordinateReceived()
will fire - If the
map
completes intialization afteronCoordinateReceived()
, thezoomTo()
in thedisplayready
listener will fire. - If the
<DIV>
update occurs last, thezoomTo()
in theresize
listener will fire, which will alter from a zoomed Out map to the "right" zoom level.