Thanks Chad, for the post. Basically, I took a look at one of the links
which provided me with enough code to go on my own. It's still not as easy
to get the position based on the LatLong of any map objects by any means. I
think the Google team should incorporate an API method to actually do this
rather than have this written out by everyone who wants to get the browser
window XY coordinates.
Anyway, if anyone wants to use this code, it's a blank overlay to get at the
projection. The only catch is that you have to initialize the overlay
object in the map's initializer method when the map loads up. Deferring the
creation of the overlay object may result in the projection object not being
available until later. So, you might get a null/undefined exception
thrown. Here's the code snippet:
function CoordinatesControl(map)
{ this.setMap(map);
}
CoordinatesControl.prototype = new google.maps.OverlayView();
CoordinatesControl.prototype.draw = function() {};
CoordinatesControl.prototype.GetWindowCoordinates = function(latLong)
{ var projection = this.getProjection();
return projection.fromLatLngToContainerPixel(latLong);
}
/*-----------Code to initialize the CoordinatesControl-------------------*/
function Map()
{ //Your map class code here
this.map = null
...
this.coordinatesControl = null; //Declare your control here.
//You can also declare and initialize your control all at once here if
your map object is also created.
}
Map.prototype.Initialize = function()
{ //This is where you initialize your map
this.map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
...
this.coordinatesControl = new CoordinatesControl(this.map);
}
...
//Within some function, you'll call the GetWindowCoordinates function from
the CoordinatesControl
...
this.coordinatesControl.GetWindowCoordinates(marker.getPosition());
//passes in the marker's latLng.
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.