I’m new to the V3 version of the maps API, having used V2 in the past. As a result, there are some map creation issues I’ve run into while trying to port our app from V2 to V3.
I’m creating a map like this now, and it seems to work– I’m returned a map object in the variable m_oGoogleMap:
m_oGoogleMap = new google.maps.Map(
$('Map'), {
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.LEFT_TOP
},
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT
},
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 8,
center: new google.maps.LatLng(LAT, LNG)
});
…However, after doing this I cannot call methods such as getBounds() or getProjection() without receiving an undefined error– I can see stubs for those methods while debugging, in the Chrome watch expressions area, but calling them there (or on the page itself) yields an undefined error. Am I missing how to create and initialize a map in V3?
Other methods on the map object, such as getDiv(), work just fine. So I’m not sure if I have a half-initialized object or what might be happening?
The creation of a map is an asynchronous process, some methods/properties are not accessible before this process has been finished. Wait for events like
idleortilesloadedbefore you access these methods.