I have an Ajax function that gets an array of markers data from the database and displays it on a Google Map. I was sucessful at getting one marker to display however i placed the ajax function on a button click event. The event fires sucessfully without any errors.
The data is returned in the form of json object. The markers are not getting drawn to the map. Under is the code:
Ajax Function
$('#getCitizens').click(function(){
var mapOptions = {center: new google.maps.LatLng(10.670044,-61.515305),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
var citizens = (function(){
var citizens = null;
$.ajax({
type: 'GET',
async : false,
global: 'false',
url: 'getListOfMarkers.htm',
headers : {Accept : 'application/json'},
dataType: 'json',
success: function(data){
citizens = data;
}
});
return citizens;
})();
for(var i= 0; i< citizens.length;i++){
console.log(citizens[i].name +' | '+citizens[i].socialSecurityNumber +' | '+citizens[i].latlng);
var markerType = citizens[i].citizenType
if(markerType = 2){
var citizen_icon = new google.maps.MarkerImage('resources/icons/a_new.ico',new google.maps.Size(100,106),new google.maps.Point(0,0),new google.maps.Point(50,50));
}else if(markerType = 3){
var b_icon = new google.maps.MarkerImage('resources/icons/b_new.ico',new google.maps.Size(100,106),new google.maps.Point(0,0),new google.maps.Point(50,50));
}else if(markerType = 4){
var citizen_icon = new google.maps.MarkerImage('resources/icons/c_new.ico',new google.maps.Size(100,106),new google.maps.Point(0,0),new google.maps.Point(50,50));
}
var citizenPosition = new google.maps.LatLng(citizens[i].latlng);
var citizenName = citizens[i].name;
var citizenMarker = new google.maps.Marker({
position: citizenPosition,
map:map,
icon:citizen_icon,
title:citizenName
});
}
})
JSON DATA
{"name":"Damien Edwards","latlng":"10.67023300000000,-61.51530500000000","socialSecurityNumber":194302025,"citizenType":3},
{"name":"Raj Hassen","latlng":"10.67030000000000,-61.51530500000000","socialSecurityNumber":198501011,"citizenType":2},
{"name":"Richard Gibbs","latlng":"10.670044,-61.515305","socialSecurityNumber":198501012,"citizenType":2},
{"name":"Sylvester Macintosh","latlng":"10.670044,-61.515305","socialSecurityNumber":1985010122,"citizenType":3},
{"name":"Howard Bugario","latlng":"10.670044,-61.515305","socialSecurityNumber":1985121244,"citizenType":4},
{"name":"Lawerence Figaro","latlng":"10.670044,-61.515305","socialSecurityNumber":1985121245,"citizenType":4},
{"name":"Jessie Small","latlng":"10.670044,-61.515305","socialSecurityNumber":1999020214,"citizenType":3}]
;