Firebug Error : markersArray[i].setMap is not a function

2,926 views
Skip to first unread message

morningstar

unread,
Aug 5, 2010, 8:00:39 AM8/5/10
to Google Maps JavaScript API v3
I'm working on a small map app and when i try to remove markers on the
map that i had placed earlier, with the following function;

function clearLocations() {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}

I get the error markersArray[i].setMap is not a function and the
markers are still on the map.Help will be appreciated.
Thanks

geoco...@gmail.com

unread,
Aug 5, 2010, 9:22:31 AM8/5/10
to Google Maps JavaScript API v3
More context please. Preferably a link to your map that exhibits the
error. The most likely cause of your problem is that the markersArray
is not in scope.

-- Larry

> Thanks

Federico Ulfo

unread,
Aug 5, 2010, 12:43:38 PM8/5/10
to google-map...@googlegroups.com
Do you have declared markersArray as global variable?
And instead of markersArray.lentgh = 0 use
markerArray = [] to initialize the array again

Bye




> Thanks

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Rossko

unread,
Aug 5, 2010, 8:53:52 PM8/5/10
to Google Maps JavaScript API v3
> I get the error markersArray[i].setMap is not a function and  the
> markers are still on the map.Help will be appreciated.

Guessing, this might be relevant -
http://stackoverflow.com/questions/500504/javascript-for-in-with-arrays

morningstar

unread,
Aug 6, 2010, 3:20:13 AM8/6/10
to Google Maps JavaScript API v3
the map is still in my localhost not online yet.But I'm making
arrangement to upload it.
I think the markersArray is in scope, cause its a global variable and
works in other functions like the one to bring in initial markers on
the map.
I also tried the other suggestions still not working.

On Aug 5, 4:22 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

Federico Ulfo

unread,
Aug 6, 2010, 4:54:00 AM8/6/10
to google-map...@googlegroups.com
like this should work

      
     function clearLocations() {
         for (i in markersArray)
              markersArray[i].setMap(null);
         markersArray = new Array()
       }

if you post your map code we can help you more

2010/8/6 morningstar <chaoticu...@gmail.com>

geoco...@gmail.com

unread,
Aug 6, 2010, 10:28:14 AM8/6/10
to Google Maps JavaScript API v3
On Aug 6, 12:20 am, morningstar <chaoticuniform...@gmail.com> wrote:
> the map is still in my localhost not online yet.But I'm making
> arrangement to upload it.
> I think the markersArray is in scope, cause its  a global variable and
> works in other functions like the one to bring in initial markers on
> the map.
> I also tried the other suggestions still not working.

Then we will need to see the patient. Give us a link when you get it
online, I would thing the problem should be obvious in a debugger.

-- Larry

morningstar

unread,
Aug 7, 2010, 4:36:39 AM8/7/10
to Google Maps JavaScript API v3
Forgot to mention, to see the error try using searching.

Rossko

unread,
Aug 7, 2010, 6:32:01 AM8/7/10
to Google Maps JavaScript API v3
> Forgot to mention, to see the error try using searching.

Can't. Can't see your webpage.

morningstar

unread,
Aug 7, 2010, 9:01:30 AM8/7/10
to Google Maps JavaScript API v3

Rossko

unread,
Aug 7, 2010, 11:10:21 AM8/7/10
to Google Maps JavaScript API v3
> www.alpha.atkariakoo.com

markersArray is a collection of XML document elements ; these do not
have a .setMap() method.

You need to build an array of API google.maps.Marker objects if you
want to clear them later.

morningstar

unread,
Aug 9, 2010, 1:39:15 AM8/9/10
to Google Maps JavaScript API v3
Ahh...thank you very much.Arrays have always been a blind spot of
mine.
Reply all
Reply to author
Forward
0 new messages