views:

130

answers:

1

in v2:

point = map.fromContainerPixelToLatLng(new GLatLng(x,y));}

in v3 i do this:

point = map.MapCanvasProjection.fromContainerPixelToLatLng(new LatLng(x,y));

and error..

how to do this?

thanks

A: 

As far as I know the map class doesn't have a MapCanvasProjection property. It's not in the specs if they've recently added one.

There's a work around you can do by creating a dummy OverlayView which will have a projection:

  /**@private 
   * In V3 it is quite hard to gain access to Projection and Panes. 
   * This is a helper class 
   * @param {google.maps.Map} map 
   */ 
  function ProjectionHelperOverlay(map) { 
    google.maps.OverlayView.call(this); 
    this.setMap(map); 
  } 
  ProjectionHelperOverlay.prototype = new google.maps.OverlayView(); 
  ProjectionHelperOverlay.prototype.draw = function () { 
    if (!this.ready) { 
      this.ready = true; 
      google.maps.event.trigger(this, 'ready'); 
    } 
  }; 

Which was taken from this open source code. You can use it like this:

var proj = new ProjectionHelperOverlay(map);
proj.getProjection().fromContainerPixelToLatLng(new LatLng(x,y));
Bob
this.set_map ??? which is this function ??
zjm1126
@zjm1126 Oops, sorry, this code must be kind of old. It's setMap()
Bob