[Google Maps API V3][Markerclusterer] I cannot use any function implemented within MarkerClusterer object

209 views
Skip to first unread message

Junsuk Bang

unread,
Nov 7, 2011, 10:55:09 PM11/7/11
to google-map...@googlegroups.com
Hi,

During making an example using markerclusterer library, I found that any of functions in this object was not working.

Here is my example, which allows you to set a marker at the point you clicked. 
Then, What I'm trying is that markerclusterer automatically clusts all the points User clicked.


However, My Google Chrome devepoling tool said that functions I used, such as addMarker() and clearMarkers(), cannot be called.

"Cannot call method "addMarker" of undefined" This is what it exactly said.

FYI, I have used libraries for v3,  http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js, and I have also tried with non-compiled(standard) version. But, Nothing was different.

If somebody has any idea, help me.

Thanks in advance.



Junsuk Bang

geoco...@gmail.com

unread,
Nov 8, 2011, 1:29:21 AM11/8/11
to Google Maps JavaScript API v3
On Nov 7, 7:55 pm, Junsuk Bang <jsb...@sphinfo.co.kr> wrote:
> Hi,
>
> During making an example using markerclusterer library, I found that any of
> functions in this object was not working.
>
> Here is my example, which allows you to set a marker at the point you
> clicked.
> Then, What I'm trying is that markerclusterer automatically clusts all the
> points User clicked.
>
> http://www.sphinfo.co.kr/sample/2011-11-07_Marker_clustering_example....
>
> However, My Google Chrome devepoling tool said that functions I used, such
> as addMarker() and clearMarkers(), cannot be called.

That is because the one that you declare in your initialize function
is local to the initialize function (the "var" keyword in there re-
declares it in the local scope).

-- Larry

>
> "Cannot call method "addMarker" of undefined" This is what it exactly said.
>
> FYI, I have used libraries for v3,  http://google-maps-utility-library-v3.googlecode.com/svn/trunk/marker...,

Junsuk Bang

unread,
Nov 8, 2011, 4:18:29 AM11/8/11
to google-map...@googlegroups.com
First of all, thank you for your response.

I found that I declared MarkerClusterer variable as a global one at the 21st line of my codes, which is

         var markerCluster = null;

I have already got this idea from the example of markerclusterer.

Would you please check it?


Thank you again.


Junsuk Bang

Rossko

unread,
Nov 8, 2011, 4:44:36 AM11/8/11
to Google Maps JavaScript API v3
> I found that I declared MarkerClusterer variable as a global one at the
> 21st line of my codes, which is
>          var markerCluster = null;

Yes, but
function initialize(){
...
var markerCluster = new MarkerClusterer(map,markers);
creates another 'markerCluster' local to initialize. The global
'markerCluster' stays null.
If you want to assign the existing global 'markerCluster' instead,
don't use the 'var' keyword

Junsuk Bang

unread,
Nov 9, 2011, 11:48:58 PM11/9/11
to google-map...@googlegroups.com
Thanks for you guys' help!

I really appreciate it!

Reply all
Reply to author
Forward
0 new messages