This project is read-only.

Javascript and GoogleMap Control

Dec 19, 2011 at 3:09 PM

Hi

Is there a way in javascript to access the map created by the Google Map Control (v6) GoogleMap API V3

Following does not work.

            function test(sender, e) {
                var map = document.getElementById("GoogleMapMonitor1_GoogleMap1");
                var zoom = map.getZoom();
                alert("Testing");
            }

I don't really know how to access/get the google map object... Any help would be appreciated - maybe with an example.

 

Dec 19, 2011 at 8:33 PM

Hi,

You don't need to use the ClientID of the control. So, in your case the ID of the control is GoogleMap1, then you can access the javascript GoogleMap control object adding maps namespace before it, like:

var map = maps.GoogleMap1;

But, if you would like to use the ClientID of the control, then I believe the proper way should be:

var map = $find("GoogleMapMonitor1_GoogleMap1");

Hope this helps.

Regards

Dec 20, 2011 at 9:08 AM

Thanks a lot - that worked

The reason for having a need for this method is to get the mapzoom and mapcenter. I had no luck in getting the mapcenter coordinates from the OnClientDragEnd event. The google map control sample code does also not return the coordinates? Error in GoogleMap Control? Maybe that is new functionality

Anyway below worked.

            function test() {
                var map = $find("GoogleMapMonitor1_GoogleMap1");
                var lat = map.getCenter().lat();
                var lng = map.getCenter().lng();
                var zoom = map.getZoom();
                var text = "Zoom=" + zoom + " Lat=" + lat + " Long=" + lng;
                alert(text);
            }

Thanks