I have the following code and I want to call initialize function here with the following;
google.maps.event.addDomListener(window, ‘load’, initialize);
But I am getting this error; Error: initialize is not defined.
What is wrong here?
$(function CheckinMap() {
$.ajax({
type: "GET",
url: "content/home/index.cs.asp?Process=ViewCheckinMap",
success: function initialize(data) {
var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP,
maxZoom: 4
});
var markers = [];
for (var i = 0; i < data.users.length; i++) {
var location = data.users[i];
var latLng = new google.maps.LatLng(location.latitude,
location.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
},
error: function (data) {
$("#checkinmap").append(data);
}
});
});
google.maps.event.addDomListener(window, 'load', initialize);
If you want to use a function for both the jQuery
successmethod and theaddDomListenerthird argument, then you have to store it somewhere when you define it rather than passing it directly tosuccess.That somewhere also has to be in scope for both your call to
ajaxand toaddDomLister.Move
function initialize(data)so it appears before your current line 1.Then say
success: initialize.