views:

39

answers:

1

I currently have a implementation where some markers coming from JSON list is shown, on a particular area, Now I want to filter these marker depending upon some criteria, I have done the filtering part, and got the filtered list. Now to render this markers on the map again, The current implementation loads the js with a key again, also creates the GMap2 object and draws the list of marker on the newly created map, which is really annoying. I want map to be there and only markers to be added and removed from the map. Any help is appreciated

A: 

You can use addOverlay and removeOverlay to add/remove markers from an already displayed map. See the examples here: http://code.google.com/apis/maps/documentation/overlays.html#Markers

var latlng = new GLatLng(lat, lng);
map.addOverlay(new GMarker(latlng));
Jakob Kruse
Well I tried that, and bypassed loading the js and creating of map object, And jumped directly to getMarkers,The getMarkers do all the creation of markers adding them to map and calling setCenter on the map. I did call clearoverlays() before this on GMap, This resulted in no generation of map at all.The container div is empty. No idea why!!!
vishwanath
I'm not at all sure what you mean. This code will add a new marker to an already displayed map, there is absolutely no need to reload the map: var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()); map.addOverlay(new GMarker(latlng));I really need to see your code to help any more than that.
Jakob Kruse
Sorry, my bad, whatever you said was exactly right and I was also in the same lane. The problem with my implementation was some initialization procedure from some different file, which was cleaning out all the map area, So that was just gave me scary thought, that I dont know google api much and there might be something I was missing.Though thanks for your help. Sorry but I cant upvote any as I am still new here.:(
vishwanath
No worries, thanks for accepting :)
Jakob Kruse