I got it working thanks to elxiduppy on another forum I post on alot.
Here is the code in case anyone else needs it. Please keep in mind
that I also add a description to the marker and I also check that. So,
if you have two markers that are in the same spot but different
descriptions, they will be seen as different.
//this function keeps an array of markers
//if the marker is on the map then it removes
//the marker. Otherwise it adds the marker
function addUserMarker(lat, lon, desc) {
var inMap = false;
var count = 0;
var loc = new GLatLng(lat, lon);
while (inMap == false && count < arrOfMarkers.length) {
//if the lattitude and longitude are on the map
//and the descriptions match each other then it is an
//existing marker.
if ((loc.lat() == arrOfMarkers[count].getLatLng().lat())
&&
(loc.lng() == arrOfMarkers[count].getLatLng().lng())
&&
(arrOfDesc[count] == desc)) {
inMap = true;
break;
}//if
count++;
}//while
if (!inMap) {
var marker = new GMarker(loc);
arrOfMarkers.push(marker);
arrOfDesc.push(desc);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(desc);
});
map.addOverlay(marker);
map.setCenter(loc, map.getZoom());
}//if
else {
map.removeOverlay(arrOfMarkers[count]);
arrOfMarkers.splice(count, 1);
arrOfDesc.splice(count, 1);
}//else
} //addUserMarker
On Aug 10, 2:02 pm, Michael Andrews <[email protected]> wrote:
> As I have been researching I have come to figure that out. So even
> though I create a new marker with the exact same coordinates, it does
> not see that as an existing marker? I have been trying to store the
> markers in an array but to no avail. Do you have any idea how I can
> keep track of whether or not my markers are showing to be able to hide
> them? Thanks for your help.
>
> On Aug 10, 11:18 am, Andrew Leach <[email protected]>
> wrote:
>
> > On Aug 10, 4:56 pm, Michael Andrews <[email protected]> wrote:
>
> > > My function works fine to add the marker, however it won't remove the
> > > marker. I cannot figure out why.
>
> > You create a local reference to your marker (tempMarker) and use that
> > to add the marker to the map. That's fine as far as it goes; but the
> > reference is destroyed when you exit the function, so you can't get at
> > the marker again after that.
>
> > Any variable you need to use more than once must be global.
>
> > You'll need to be careful of just using "arrOfCord" inside a function
> > too. That should be explicitly defined as a global variable so that
> > the code behaves identically in different browsers.
>
> > Andrew
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---