I add the markers in basically the same manner. What I am trying to do
now though, is to remove them if they are on the map. However my code
is not working. Here is my code and here is the page
http://alpha.clickablecommunity.com
function loadEarth(mapdiv) {
arrOfCord = new Array();
if (GBrowserIsCompatible()) {
var point;
if (!mapdiv) return true;
//find the div
map = new GMap2(document.getElementById(mapdiv));
//this will add a map overview in the bottom
//right hand corner
//map.addControl(new GOverviewMapControl());
//enable the zooming
map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
//call the function that adds the menu
//when the user right clics
createContextMenu(map, mapdiv);
//add the different map types i.e. satellite street
hybrid
map.addControl(new GMapTypeControl());
//add the zoom + and - buttons
map.addControl(new GSmallMapControl());
//set the center, position, and type of map to start
with
map.setCenter(new GLatLng(40.7001, -99.0844), 15);
map.setMapType(G_NORMAL_MAP);
//if we wanted to draw a polyline we would uncomment
this code
//var polyline = new GPolyline([new GLatLng(37.4419,
-122.1419),
//new GLatLng(37.4519, -122.1519),
//new GLatLng(37.4619, -122.1819)], "#3333cc", 10);
//map.addOverlay(polyline);
} //if gbrowseriscompatible
else {
document.getElementById(mapdiv).innerHTML = "Sorry,
your browser is not compatible" +
"with our maps
application<br>" +
"Please try
updating to a newer version of your browser.";
}
} //loadEarth
//this function takes in the lat lon and description.
//it checks an array of coordinates and if the coordinates
//are in the array then it removes the marker.
//if they are not in the array then we add them to
//the array and add the marker. keeping the coordinates
//in an array is how I check to see if the marker exists.
function addUserMarker(lat, lon, desc) {
//a string version of our coordinates
//to check the array of coordinates with
var tempCord = lat.toString() + lon.toString();
//we set this to false if it stays that way
//then the coordinates are not in the array
//meaning it's not on the map so we add it
var inMap = false;
var count = 0;
//create the new marker
var tempMarker = new GMarker(new GLatLng(lat, lon));
while (inMap === false && count < arrOfCord.length) {
//if it is in the array then the coordinate is already
//a marker on the map
if (tempCord == arrOfCord[count]) {
inMap = true;
} //it tempCord
count++;
} //while
//if this stayed false then we add it to the map
if (inMap === false) {
arrOfCord.push(tempCord);
//add the description popup box
GEvent.addListener(tempMarker, "click", function() {
tempMarker.openInfoWindowHtml(desc);
});
map.addOverlay(tempMarker);
map.setCenter(new GLatLng(lat, lon), map.getZoom());
} //if inMap
//we need to remove the marker
else {
//remove the marker from the map
map.removeOverlay(tempMarker);
//remove it from the array
arrOfCord.splice(arrOfCord.indexOf(tempCord), 1);
} //else
} //addUserMarker
Any thoughts? Thanks,
On Aug 4, 4:47 pm, Grok Lobster <[email protected]> wrote:
> Have you seen Mike's tutorial?http://econym.org.uk/gmap/example_map2.htm
> That example has the markers already displayed before hand but there's
> no reason you can't perform the map.addOverlay on the click.
>
> On Aug 4, 12:17 pm, Michael Andrews <[email protected]> wrote:
>
> > I have a page you can view
> > herehttp://alpha.clickablecommunity.com/index.aspx
> > Right now I have two static markers. If you look on the left side, you
> > will see generic category 1 category 2 with events beneath them. What
> > I want is when a user clicks on one of those events for the map to
> > change it's center position to that lat/long and put a marker there,
> > if they click on another link I want the center to change, but the
> > marker to stay so if they clicked on 4 links, then there should be 4
> > markers. Also, if they have clicked on a link and they click on it
> > again, I want to remove the marker. I can understand the pseudo on how
> > to do this, but I have no idea on the code. Can anyone either help me
> > or at least point me in the right direction? Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---