I would like to display or hide some markers when a user click on a checkbox. I'm using Gmaps.js and the code responsible for this is:
// Check if the user wants to display points of interest
$("#poi").click(function() {
var poi_markers = [];
if ($("#poi").is(':checked')) {
// Get points of interest and display them on the map
$.ajax({
type: "POST",
url: "/ajax/poi.php",
dataType: "JSON",
cache: false,
success: function(data) {
$.each(data, function(key, value) {
poi_marker = {
marker: {
lat: value.latitude,
lng: value.longitude,
icon: '/images/marker-sight.png',
infoWindow: {
content: value.name
}
}
}
poi_markers.push(poi_marker);
});
console.log(poi_markers);
map.addMarkers(poi_markers);
}
});
} else {
map.removeMarkers(poi_markers);
}
});
Sample JSON:
[{"name":"Biserica Neagra","latitude":"45.640981","longitude":"25.587723"}]
In Firebug I get this error: "uncaught exception: No latitude or longitude defined.".
What am I doing wrong?