I have these two functions. One that loads the map on the page load
and the other that adds a marker when a client clicks a link. If you
want to see what I am trying to do you can go here 
http://alpha.clickablecommunity.com/
My function works fine to add the marker, however it won't remove the
marker. I cannot figure out why. Can someone please help me, I have
been racking my brain on this for almost a week now. Thanks,
        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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to