Google Maps V3: Loading infowindow content via AJAX
for (var i = 0; i < markersClient.length; i++) {
var location = new google.maps.LatLng(lats[i], longs[i]);
var marker = new google.maps.Marker({
position: location,
map: map,
lid: markersClient[i].t
});
var infowindow = new google.maps.InfoWindow({
content: ""
});
//debugger;
marker.setTitle(" - ");
markers.push(marker);
google.maps.event.addListener(marker, 'click', function (target, elem) {
infowindow.open(map, marker);
$.ajax({
success:function () {
infowindow.setContent(contentString);
}
});
intitalize map , marker , infowindow(as no content) and on marker 's click handler make ajax request
You can call infowindow.setContent at any point after the info window has been shown. So you could initially set your info window content with a spinner, make the AJAX call (from the event handler) and then call infowindow.setContent again from the AJAX response with the appropriate data.