I'm trying to put markers on my google map canvas by fetching the info out of the database, I followed every step from https://developers.google.com/maps/articles/phpsqlajax_v3 though somehow it doesnt work (probably because I changed a few things, though I cant find what brings the troubles up.)
I already managed to fetch the data by using a phptoxml.php file the dummy output proves that It's correct I guess:
<users>
<user id="1" name="John Tucker" age="19" lat="47.608940" lng="-122.340141" type="0"/>
<user id="2" name="Dean Jester" age="21" lat="51.219040" lng="4.326590" type="0"/>
<user id="3" name="Joris Nisteven" age="26" lat="51.203671" lng="4.341480" type="0"/>
<user id="4" name="Joske Vermeulen" age="20" lat="51.204155" lng="4.327018" type="0"/>
<user id="5" name="Timmy den Beir" age="21" lat="51.209263" lng="4.339720" type="0"/>
<user id="6" name="Ben von Duppen" age="23" lat="51.168308" lng="4.394287" type="0"/>
</users>
now the code that I use to fetch the data and put it in variables:
downloadUrl("phptoxml.php", function(data) {
var xml = data.responseXML;
var users = xml.documentElement.getElementsByTagName("user");
for (var i = 0; i < users.length; i++) {
var id = parseInt(users[i].getAttribute("id"));
var name = users[i].getAttribute("name");
var age = parseInt(users[i].getAttribute("age"));
var lat = parseFloat(users[i].getAttribute("lat"));
var lng = parseFloat(users[i].getAttribute("lng"));
var marker = add_marker(lat,lng,id,name,age); // pass in as Latitude, then Longitude
fluster.addMarker(marker);
}
});
where fluster is used for cluster management and the function add_marker worked well before, so I doubt that that could be the problem.
the function downloadUrl is defined as followed (though this part of the code is pretty vague for me)
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);
}
I noticed that if I put an alert behind request.send(null); with debug info, it doesnt pop up. same for any alert that comes after the downloadUrl call..
I have no clue, hope someone might help :)
Ty in advance
for more info i include the entire code:
<script type="text/javascript">
var map; var fluster; var infoBubble;
function initialize() {
var latlng = new google.maps.LatLng(27.059125784374068,-37.6171875);
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
fluster = new Fluster2(map);
// Change this depending on the name of your PHP file
downloadUrl("phptoxml.php", function(data) {
var xml = data.responseXML;
var users = xml.documentElement.getElementsByTagName("user");
for (var i = 0; i < users.length; i++) {
var id = parseInt(users[i].getAttribute("id"));
var name = users[i].getAttribute("name");
var age = parseInt(users[i].getAttribute("age"));
var lat = parseFloat(users[i].getAttribute("lat"));
var lng = parseFloat(users[i].getAttribute("lng"));
var marker = add_marker(lat,lng,id,name,age); // pass in as Latitude, then Longitude
fluster.addMarker(marker);
}
});
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
var address = '';
if (place.address_components) {
address = [(place.address_components[0] &&
place.address_components[0].short_name || ''),
(place.address_components[1] &&
place.address_components[1].short_name || ''),
(place.address_components[2] &&
place.address_components[2].short_name || '')
].join(' ');
}
});
// Initialize Fluster
// This will set event handlers on the map and calculate clusters the first time.
fluster.initialize();
}
function add_marker(lat,lng,id,name,age) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map,
icon: 'suiticon.png',
title: name
});
var infoBubble = new InfoBubble({
maxWidth: 300,
backgroundColor: '#dedddd',
borderWidth: 2,
borderColor: 'rgb(68, 68, 68)'
});
var contentString = '<div id="content">'+
/*'<h2>'+name+'</h2>'+
'<p><span class="myLabel" style="margin-right:10px">'+age+'</span>21</p>'+
'<p><center><img src="'+id+'.jpg" class="bro_image"></center> </p>'+
'<p><button class="button_inverse" style="padding-left: 23px; padding-right:23px; margin-left:31px;" href="#">Rate this Bro!</button></p>'+
*/'</div>';
var div = document.createElement('DIV');
div.innerHTML = 'No pictures uploaded by this user.';
infoBubble.addTab('Personal', contentString);
infoBubble.addTab('Pictures', div);
google.maps.event.addListener(marker, 'click', function() {
if (!infoBubble.isOpen()) {
infoBubble.open(map, marker);
}
});
return marker;
}
function addTab() {
var title = document.getElementById('tab-title').value;
var content = document.getElementById('tab-content').value;
if (title != '' && content != '') {
infoBubble.addTab(title, content);
}
}
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);
}
</script>