Projection is undefined

682 views
Skip to first unread message

Kyle Pena

unread,
Oct 18, 2010, 12:56:51 AM10/18/10
to Google Maps JavaScript API v3
Hi folks - my end game is calling the function
fromContainerPixelToLatLng, but in order to get there, I need an
instance of projection to play with. But projection is undefined no
matter how hard I try.
Code:

function getGMap() {
var myLatlng = new google.maps.LatLng(...elided...);
var myOptions = {
zoom: 19,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.SATELLITE,
draggable: true, /* You can move by dragging around */
scaleControl: false, /* But the control is not visible */
disableDefaultUI: true, /* Remove all the distracting
google maps UI stuff */
disableDoubleClickZoom: true, /* And you can't double
click to zoom */
scrollwheel: false /* And you can't scroll to zoom */
};
var map = new google.maps.Map($(".map")[0], myOptions);

// set up a prototype for google maps
MyOverlay.prototype = new google.maps.OverlayView();
MyOverlay.prototype.onAdd = function() { };
MyOverlay.prototype.onRemove = function() { };
MyOverlay.prototype.draw = function() { };
function MyOverlay(map) { this.setMap(map); };

// set up the GMap overlay (not the same as the HTML5 overlay
I made)
// without setting up this overlay, google maps won't be able
to get an instance of the projection, which we need for unit
calculations
var overlay = new MyOverlay(map);
var projection = overlay.getProjection();
MyApp.Projection = projection;
return map;
};

What's wrong?

geoco...@gmail.com

unread,
Oct 18, 2010, 1:20:50 AM10/18/10
to Google Maps JavaScript API v3
As a guess (since you didn't provide a link to your map):
You need to wait for the projection_changed event to fire, indicating
the projection has been configured.

-- Larry
Reply all
Reply to author
Forward
0 new messages