Answering my own question. I made it work by wrapping the code below
into the initialize() function as below.

This *doesn't work*:

  google.load("maps", "2.x",  {other_params:"sensor=false"});
  google.setOnLoadCallback(initialize);

  try {
    function NewOverlay () {}
    NewOverlay.prototype = new google.maps.Overlay();
    alert(NewOverlay.toString());
  }
  catch (e) { alert(e); }

  function initialize() {
    var map = new google.maps.Map2(document.getElementById
("map_canvas"));
    map.addControl(new GSmallZoomControl3D());
    map.setCenter(new GLatLng(-34.397, 150.644), 8);
  }

but this *does work* (try {} catch{} is inside initialize()):

  google.load("maps", "2.x",  {other_params:"sensor=false"});
  google.setOnLoadCallback(initialize);

  function initialize() {

  try {
    function NewOverlay () {}
    NewOverlay.prototype = new google.maps.Overlay();
    alert(NewOverlay.toString());
  }
  catch (e) { alert(e); }

    var map = new google.maps.Map2(document.getElementById
("map_canvas"));
    map.addControl(new GSmallZoomControl3D());
    map.setCenter(new GLatLng(-34.397, 150.644), 8);
  }

It's a bit inconvenient to have it all inside the initialize()
function, but because it's loaded asynchronously, there is probably no
other way to do that.

Also, the documentation could be more clear on this, although it does
mention "Perform any initialization to your objects using
google.setOnLoadCallback()".

Paul.

On Sep 23, 4:45 pm, Paul Kulchenko <[email protected]> wrote:
> I have a very simple map (http://my-test.dreamhosters.com/
> commonloader2.html) that is using AJAX API to load maps interface. The
> map itself loads fine, but when I try to work with loaded classes (for
> example, create new objects based on them) I get this error:
> google.maps.Overlay is not a constructor. This is caused by something
> as simple as:
>
>     function NewOverlay () {}
>     NewOverlay.prototype = new google.maps.Overlay();
>
> The AJAX loader documentation is straightforward (http://
> code.google.com/apis/maps/documentation/#AJAX_Loader): Use the
> google.maps.* namespace for all classes, methods and properties you
> currently use in the Google Maps API, replacing the G prefix with this
> namespace.
>
> Based on this description I replaced "new GOverlay()" with "new
> google.maps.Overlay()". What am I doing wrong here?
>
> Paul.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to