Skip to content Skip to sidebar Skip to footer

Link Multiple Markers From Xml On Google Maps

I was able to pull in my markers from an XML file and place them on a Google Map, but now I want each marker to link to its respective url once clicked. Can someone please let me k

Solution 1:

Make a create Marker function like this (not tested):

functioncreateMarker(point, url) {
    var marker = new google.maps.Marker({
        position: point,
        map: googleMap,
        icon: 'map-pin.png',
        url: markerUrl
    });
    google.maps.event.addListener(marker, 'click', function() {
        window.location.href = marker.url;
    });
}

Then call it like this:

downLoad("phpsqlajax.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
        var city = markers[i].getAttribute("city");
        var state = markers[i].getAttribute("state");
        var country = markers[i].getAttribute("country");
        var markerUrl = markers[i].getAttribute("url");
        var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
        createMarker(point, markerUrl);
    }
});

Post a Comment for "Link Multiple Markers From Xml On Google Maps"