Я вижу по крайней мере несколько вопросов здесь:
- вы используете переменную
map
в цикле for перед его инициализацией. Я бы инициализировал карту вне обратного вызова getJSON;
- Вы не установили опцию центра;
- вы можете не увидеть карту, если $ .getJSON не удастся - используйте
console.log
или точки останова, чтобы увидеть, оцениваются ли все ожидаемые вами строки;
- вы не импортируете jQuery для использования $ .getJSON
попробуйте эту обновленную initMap
функцию:
function initMap() {
var marker, i;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: new google.maps.LatLng(0, 0);
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow({});
$.ajax({
url: "polarServer.asp?Screen=GetBlobScript&Script=LocationMap_GetMapData&SID=<%Context.WebSession.SessionIDcode%>",
dataType: 'json',
success: function(pLocations) {
if (pLocations instanceof Array) {
for (i = 0; i < pLocations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(pLocations[i].lat, pLocations[i].lon),
map: map
});
google.maps.event.addListener(marker, 'Click', function () {
infowindow.setContent(pLocations[i].info);
infowindow.open(map, marker);
});
}
if (pLocations.length > 0) {
map.setCenter(new google.maps.LatLng(pLocations[0].lat, pLocations[0].lon));
}
} else {
console.error("serve response is not an Array");
}
},
error: function(err){
console.error("Failed to get the data: ", err);
}
});
}
и убедитесь, что JQuery встроен в ваш код