I'm currently developing a web application that uses google maps and ajax. I'm both new to the technologies so I'm not sure if I'm doing things right. I followed the instructions on how to create one at https://developers.google.com/maps/articles/phpsqlsearch_v3. here's the snippet of my code:
function searchNearLocations(radius){
var searchUrl = './designIncludes/phpLogicIncludes/searchMarkers.php?lat=' + myLat +'&lng=' + myLng + '&radius=' + radius;
downloadUrl(searchUrl, function(data) {
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
var bounds = new googlemaps.LatLngBounds();
for (var i = 0; markerNodes.Length; i ++){
var name = markerNodes[i].getAttribute("name");
var address = markerNodes[i].getAttribute("address");
var info = markerNodes[i].getAttribute("info");
var tts = markerNode[i].getAttribute("tts");
var slatlng = new google.maps.LatLng(
parseFloat(markerNodes[i].getAttribute("lat")),
parseFloat(markerNodes[i].getAttribute("lang")));
createOption(name,distance,i);
createMarker(latlng,name,address);
bounds.extend(latlng);
}
map.fitBounds(bounds);
});
};
function createMarker(slatlng,name,address,info,tts){
var html = "<b>" + name + "</b></br><u>" + address + "</u></br>" + info + "</br>" + "Time allowance to spend: " + tts;
var marker = new google.maps.Marker({
map:map,
position:slatlng
});
google.maps.event.addListener(marker,'click',function(){
infoWindow.setContent(html);
infoWindow.open(map,marker);
});
markers.push(marker);
};
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.responseText, request.status);
}
};
request.open('GET',url,true);
request.send(null);
};
function parseXml(str){
if (window.ActiveXObject){
var doc = new ActiveXObject('MicrosoftXMLDOM');
doc.loadXML(str);
return doc;
}else if (window.DOMParse){
return (new DOMParser).parseFromString(str,'text/xml');
}
};
function doNothing(){};
I don't know why but when i use the console window of Mozilla I always get the error code xml is undefined.. i don't know what to do because I am really new to both technologies specially javascript. When i click the error i points me to
var markerNodes = xml.documentElement.getElementsByTagName("marker");
I don't even know how to check if my php script is working right. I'm using mysqli instead of the mysql on the google map tut link above. I hope that you guys can help me. If this is a duplicate then please send me a link.