This is probably a ridiculously simple question.
I am trying to show a map, where marker infowindow will show the following content:
Name
Address
About (ie, description)
URL
Markers are queried from a mySQL database using PHP. The code is currently mapping all markers correctly, but only shows the “name” attribute in the infowindow. What is the missing code necessary to add the 3 other attributes? (Address, About, URL?) My guess is that there’s something at this point in the code that needs adjustment:
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i].getAttribute("name"));
infowindow.open(map, marker);
}
})(marker, i));
If possible, please answer with the necessary script!
-Live link to database output: http://www.oaktonjapan.com/testmap/testcode3.php
**Note that the 1st (PAX Coworking) and last (Venture Generation) are populated with “address, about, and URL content.
-Live link to existing output: http://oaktonjapan.com/testmap/testmap5.html
**Click on the red sumo wrestler marker. This marker should show all 4 attributes if coded correctly…
Current Code:
function load() {
var cluster = [];
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(35.681382,139.766084),
zoom: 14,
mapTypeId: 'roadmap'
});
var infowindow = new google.maps.InfoWindow();
var min = .999999;
var max = 1.000001;
// Change this depending on the name of your PHP file
downloadUrl("testcode3.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var about = markers[i].getAttribute("about");
var url = markers[i].getAttribute("url");
var offsetLat = markers[i].getAttribute("lat") * (Math.random() * (max - min) + min);
var offsetLng = markers[i].getAttribute("lng") * (Math.random() * (max - min) + min);
var point = new google.maps.LatLng(offsetLat, offsetLng);
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
content: html
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i].getAttribute("name"));
infowindow.open(map, marker);
}
})(marker, i));
cluster.push(marker);
}
var mc = new MarkerClusterer(map,cluster);
});
}
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);
}
function doNothing() {}
Thanks in advance for helping out!
I would have thought you would be getting a variable not defined error on “html”.
This is where you get the data out of the xml:
This would combine it into the list you specified above:
This would display it in the infowindow (don’t know why you have the “content: html” there, but at least now it won’t cause an error):