Manipulating a Google map outside of the map object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JimpsEd
    New Member
    • Feb 2008
    • 1

    Manipulating a Google map outside of the map object

    Hi all,

    This is not a Google Map's question per se, but probably a simply JavaScript concept I am missing. I'll describe the scenario nonetheless.

    My map is loaded into:

    [HTML]<div id="map"></div>[/HTML]

    And constructed by calling the standard (for the Google Map API) load() function.

    Code:
    function load() 
    {
        // Check if the browser is compatiable with Google Maps
        if ( GBrowserIsCompatible() ) 
        {
            // Load a new map in the DIV id="map"
            var map = new GMap2(document.getElementById("map"));
    
            // Add the map controls
            map.addControl(new GMapTypeControl(1));
            map.addControl(new GLargeMapControl());
            map.addControl(new GScaleControl());
        }
    }
    I want to change the location of the map when a link is clicked on the page, such as:

    [HTML]<p><a href="javascrip t:void(0);" onclick="map.pa nTo(new GLatLng(1.46904 7,-3.601271));">Lo cation 1</a></p>[/HTML]

    However, in this link "map" is out of context; how do I reselect it?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    "map" is a local variable. Make it global by declaring it outside load().

    Comment

    Working...