"this" is the issue. Literally. You have a scope issue.

function addToMap(response){
   ...
   this["store" + i] = new GMarker(point, {icon:icon});

"this" refers to your addToMap(...) function which I don't believe you
intended to also be the data array?

I think you need to declare an Array() (e.g. markerArray) outside of
your "addToMap(..)" function.

...
var marker;
var markerArray;
var directions;
...
function initialize() {
   ...
   markerArray = new Array();
...
function addToMap(response){
   ...
   markerArray["store" + i] = new GMarker(point, {icon:icon});


Not necessary, but here's a nice associative array/hash implementation
to make working with the markerArray easy:
http://www.mojavelinux.com/articles/javascript_hashes.html

Stephen Howard


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jonny
Sent: Thursday, April 23, 2009 11:54 AM
To: Google Maps API
Subject: removeOverlay(marker) + creating variable name on the fly for
each marker


FULL CODE: http://www.jonathangoode.co.uk/map.txt
SNIPPET OF PROBLEM: http://www.jonathangoode.co.uk/snippet.txt

Hi, basically I am using GDownloadUrl() to parse an xml file of
supermarket locations. To begin with I use Loki to discover my
location automatically and when it has done so it adds a red marker to
the map of where it thinks I am.

I then add all the supermarkets (as separate markers) to the map which
fall within a 1 mile radius of my location - this all works fine. Now
the way I've set it up if Loki gets my location wrong I've made it so
the red marker is draggable so the user can correct their location.

Now my problem is on dragend of the marker I want the map to be
updated with any new supermarkets which are now within a 1 mile radius
of my updated location - I CAN do this. BUT what I can't do is remove
(removeOverlay()) the supermarkets (markers) which are no longer
within a 1 mile radius.

Part of the problem has to do with creating each javascript variable
name for each supermarket (marker) on the fly so I don't know how to
keep track of each one???

E.g. within the for loop of parsing the xml document I do:
if(calculateHaversineDistance(...) <= 1){ //1mile radius
    this["store" + i] = new GMarker(point, {icon:icon});
    map.addOverlay(this["store" + i]);  
}

I've tried using clearOverlays() but then I'm having issues with re-
adding my red marker again so I'd really like to use removeOverlay()
instead and just remove what I need to. I also tried hide() and show()
but to no avail.

Any help would be much appreciated!
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to