ankitjain11
ankitjain11

Reputation: 253

Google Maps External link for infowindow

I've a Google maps setup, where the data is coming from mySql backend and I'm storing in as encoded string. I can display the data in the map properly, but can't provide an external link.

    for (x = 0; x < stringArray.length; x = x + 1)
    {
        var addressDetails = [];
        var marker;
        //Separate each field
        addressDetails = stringArray[x].split("&&&");
        //Load the lat, long data
        var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
        //Create a new marker and info window
        var y = x+1;
        marker = new google.maps.Marker({
            map: map,
            position: lat,
            content: addressDetails[0],
            icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+y+'|FF0000|000000'
        });
        //Pushing the markers into an array so that it's easier to manage them
        markersArray.push(marker);

        google.maps.event.addListener( marker, 'click', function () {
            closeInfos();
            var info = new google.maps.InfoWindow({content: this.content});
            //On click the map will load the info window
            info.open(map,this);
            infos[0]=info;
        });
       //Extends the boundaries of the map to include this new location
       bounds.extend(lat);
    }
    //Takes all the lat, longs in the bounds variable and autosizes the map
    map.fitBounds(bounds);

And this code is for external click.

    function myclick(i) {
      google.maps.event.trigger(markersArray[i], "click");
    }

The error I'm getting is: "Uncaught ReferenceError: myclick is not defined"

Please guide where I've gone wrong?

Thanks,

Upvotes: 1

Views: 499

Answers (1)

Andr&#233; Dion
Andr&#233; Dion

Reputation: 21708

Given the way you're trying to call myclick, you'd need to attach it to your window object:

window.myclick = function(i) {
    console.log('I am defined and available in the global scope via window!');
}

Here's a demo.

Upvotes: 1

Related Questions