Problem number 1
addMarkers()
the function takes an array of markers as a parameter. But you give it an array of objects with a marker property. They should be declared in this way:poi_marker = {
lat: value.latitude,
lng: value.longitude,
infoWindow: {
content: value.name
}
}
Problem number 2
removeMarkers() , . :
map.removeMarkers();
/
, , , , Ajax , :
var gMarkers = {}, realMarkers = {};
gMarkers['bars'] = [
{lat:"45.640981",lng:"25.587723",infoWindow:{content:"Irish Pub"}},
{lat:"45.645911",lng:"25.582753",infoWindow:{content:"Beer King"}}
];
gMarkers['transportation'] = [
{lat:"45.645981",lng:"25.590723",infoWindow:{content:"Subway"}},
{lat:"45.640981",lng:"25.583723",infoWindow:{content:"Train"}},
{lat:"45.636981",lng:"25.580723",infoWindow:{content:"Airport"}}
];
, Object gMarkers, g Gmaps.js, Google Maps, . realMarkers.
Gmaps.js / , 2 , .
addMarkersOfType()
GMaps.prototype.addMarkersOfType = function (poi_type) {
realMarkers[poi_type]=[];
for(var i=0; i<gMarkers[poi_type].length; i++){
var marker = map.addMarker(gMarkers[poi_type][i]);
realMarkers[poi_type].push(marker);
}
}
removeMarkersOfType()
GMaps.prototype.removeMarkersOfType = function (poi_type) {
for(var i=0; i<gMarkers[poi_type].length; i++){
realMarkers[poi_type][i].setMap(null);
}
realMarkers[poi_type]=[];
}
$("#bar_poi").click(function() {
if ($(this).is(':checked'))
map.addMarkersOfType("bars");
else
map.removeMarkersOfType("bars");
});