When I run the code below it fails. I've run the exact same code without the ID appended to the url and it worked just fine. Am I appending it incorrectly?

// CALLS THE PHPSLQAJAX_GENXML2 PAGE AND RETURNS VALUES 
    function downloadUrl(url, callback){
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;

        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                request.onreadystatechange = doNothing;
                callback(request, request.status);
            }
        };

        request.open('GET', url, true);
        request.send(null);

    }   

    //https://developers.google.com/maps/documentation/javascript/examples/marker-remove
    function addMarker(locid) {
        var infoWindow = new google.maps.InfoWindow;

        downloadUrl("location.php?id=" . locid , function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var id = markers[i].getAttribute("id");
                var name = markers[i].getAttribute("name");
                var type = markers[i].getAttribute("type");
                var icon = markers[i].getAttribute("icon");
                var point = new google.maps.LatLng(
                    parseFloat(markers[i].getAttribute("lat")),
                    parseFloat(markers[i].getAttribute("lng"))
                );
                var html =  "<div class='title'>" + name + 
                            "</div><div class='basicinfo'><div class='addr'>" + address + 
                            "</div><div class='website'></div><div class='phone'>" + phone + 
                            "</div>";
                var marker = new google.maps.Marker({
                    position: map,
                    position: point,
                    icon: icon
                });
                bingInfoWindow(marker, map, infoWindow, html);
                markers.push(marker);
            }
        });
    }

I actually fixed my issue. I was using a . instead of a + . Changed it and that part works.

I now have a new problem though. I have a global variable declated called markers. When I try to push data to it, I get an error saying that push is not a valid function. Can anyone help?

Okay. I declared my array lik this outside the function.
var markers = [];

This is my function that is calling the markers array.

function addMarker(locid) {

        deleteMarkers();

        var infoWindow = new google.maps.InfoWindow;
        var url = "location.php?id=" + locid;

        downloadUrl(url, function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var id = markers[i].getAttribute("id");
                var name = markers[i].getAttribute("name");
                var address = markers[i].getAttribute("address");
                var phone = markers[i].getAttribute("phone");
                var type = markers[i].getAttribute("type");
                var icon = markers[i].getAttribute("icon");
                var point = new google.maps.LatLng(
                    parseFloat(markers[i].getAttribute("lat")),
                    parseFloat(markers[i].getAttribute("lng"))
                );
                var html =  "<div class='title'>" + name + 
                            "</div><div class='basicinfo'><div class='addr'>" + address + 
                            "</div><div class='website'></div><div class='phone'>" + phone + 
                            "</div>";
                var marker = new google.maps.Marker({
                    map: map,
                    position: point,
                    //icon: icon.icon
                    icon: './img/pins/gold2.png'
                });
                bindInfoWindow(marker, map, infoWindow, html);

                markers.push(marker);
            }
        });
    }

Ok so you declared markers as an global array then you declared it again as a local variable.( var markers = xml.documentElement.getElementsByTagName("marker"); ) so none of the data from the xml will be in marker outside of that function.

We know that markers is a global array so push should work. I think I would look at marker and see what is in it. For you to be getting a "push is not a valid function" error I would think that the variable marker is empty or the data is not set right ( ...., ...., .... )

Thank you for that catch. I've been trying to paste two help articles together and forgot to name one of those instances to something else. I named my global to markers_temp and everything works great now. Thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.