Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-01-2012, 09:03 PM   PM User | #1
dylanbaumannn
Regular Coder

 
Join Date: Feb 2012
Location: Nebraska, USA
Posts: 132
Thanks: 8
Thanked 19 Times in 19 Posts
dylanbaumannn is an unknown quantity at this point
Question Google Maps V3 - "MarkerClusterer is undefined"

Hello!

I'm currently working with a googlemaps (version 3) on a new site we're constructing and we're looking at attempting to implement the MarkerClusterer feature.

I've dug through the google documentation as well as a multitude of stackoverflow and independent blog posts about how to implement the MarkerClusterer however I'm still not understanding how to implement it properly.

Javascript (simplified)
Code:
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.tools.min.js"></script>

<script src="http://maps.googleapis.com/maps/api/js?v=3.9&sensor=false" type="text/javascript"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="type/javascript"></script>


<script type="text/javascript">
    var locations = [

    ['Corporate 3 DesignThis is where I work. i work with great people.', 41.249412, -96.03073, 1],
    ['This is simply a testThis is the info', 41.252615, -96.1338, 2]
    ];
	var mapOptions = {
	zoom: 10,
	center: new google.maps.LatLng(41.22,-95.95),
	mapTypeId: google.maps.MapTypeId.ROADMAP
	};
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
    var infowindow = new google.maps.InfoWindow();
    var marker, i;
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
	
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i)); 
	  
    }
  </script>
Yes the map is working, yes the points are working, yes the infobubbles are pulling through. However I'm getting the error of "MapClusterer is undefined" despite having called the MarkerClusterer.js file which explicitly creates the function named "MarkerClusterer".

any help on this would rock and I'm sure if anyone else has this problem it'd be a relief to find a solution
dylanbaumannn is offline   Reply With Quote
Old 11-02-2012, 02:35 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I don't get that error with the code provided, but then I don't see any attempt to use the marker clusterer in the code you have posted either.

I think you might need to post some code that is not quite so simplified, or maybe a link to your actual map
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
dylanbaumannn (11-05-2012)
Old 11-05-2012, 10:10 PM   PM User | #3
dylanbaumannn
Regular Coder

 
Join Date: Feb 2012
Location: Nebraska, USA
Posts: 132
Thanks: 8
Thanked 19 Times in 19 Posts
dylanbaumannn is an unknown quantity at this point
Sorry about that, I have updated the markerCluster in this version. There was a submission right before I copied the snippet of code and did not realize that it didn't include the MarkerClusterer.

Still the same errors are coming through, MarkerClusterer is undefined despite the fact that the js is included and defines the markerclusterer


Quote:
Originally Posted by xelawho View Post
I don't get that error with the code provided, but then I don't see any attempt to use the marker clusterer in the code you have posted either.

I think you might need to post some code that is not quite so simplified, or maybe a link to your actual map
Code:
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.tools.min.js"></script>

<script src="http://maps.googleapis.com/maps/api/js?v=3.9&sensor=false" type="text/javascript"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="type/javascript"></script>


<script type="text/javascript">
    var locations = [

    ['Corporate 3 DesignThis is where I work. i work with great people.', 41.249412, -96.03073, 1],
    ['This is simply a testThis is the info', 41.252615, -96.1338, 2]
    ];
	var mapOptions = {
	zoom: 10,
	center: new google.maps.LatLng(41.22,-95.95),
	mapTypeId: google.maps.MapTypeId.ROADMAP
	};
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
    var infowindow = new google.maps.InfoWindow();
    var marker, i;
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
	
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i)); 
	var markerCluster = new MarkerClusterer(map, markers);  
    }
  </script>

Here is the updated snippet with the marker clusterer is defined with the error coming through properly
dylanbaumannn is offline   Reply With Quote
Old 11-05-2012, 11:09 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
There are a couple of problems here. The error you are getting is because you are not declaring the script type correctly. This line:
Code:
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="type/javascript"></script>
should be this:
Code:
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="text/javascript"></script>
The next thing is that the second argument of the markerclusterer is supposed to be an array of markers, but you are passing it a variable "markers" which you have not defined. what you would want to do is create an empty array, push your markers onto it, then pass that array (outside of the marker creation loop) to the clusterer. Something like this, I am guessing:

Code:
<script type="text/javascript">
var markers=[];
    var locations = [

    ['Corporate 3 DesignThis is where I work. i work with great people.', 41.249412, -96.03073, 1],
    ['This is simply a testThis is the info', 41.252615, -96.1338, 2]
    ];
	var mapOptions = {
	zoom: 10,
	center: new google.maps.LatLng(41.22,-95.95),
	mapTypeId: google.maps.MapTypeId.ROADMAP
	};
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
    var infowindow = new google.maps.InfoWindow();
    var marker, i;
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
	
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i)); 
	markers.push(marker)
    }
	var markerCluster = new MarkerClusterer(map, markers);  
  </script>
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
dylanbaumannn (11-06-2012)
Old 11-05-2012, 11:42 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,064 Times in 4,033 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...Xelawho, the two <script> tags that you posted are IDENTICAL.

Here they are, both in a single block:
Code:
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="type/javascript"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="text/javascript"></script>
And here is his (red) compared to yours (blue):
Code:
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="type/javascript"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" type="text/javascript"></script>
What are you seeing that my blind eyes don't see?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 11-05-2012 at 11:44 PM..
Old Pedant is offline   Reply With Quote
Old 11-06-2012, 12:19 AM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Code:
... type="type/javascript">
vs.
Code:
... type="text/javascript">
xelawho is offline   Reply With Quote
Old 11-06-2012, 12:42 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,064 Times in 4,033 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! I was looking at the URL and flat out missed that. Yes, I do need new eyes. Or maybe a new brain.

"Igor! Where are you? I need you to make a withdrawal down at the brain bank."
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-06-2012, 02:48 PM   PM User | #8
dylanbaumannn
Regular Coder

 
Join Date: Feb 2012
Location: Nebraska, USA
Posts: 132
Thanks: 8
Thanked 19 Times in 19 Posts
dylanbaumannn is an unknown quantity at this point
Smile Thank youuuuuu

Quote:
Originally Posted by xelawho View Post
Code:
<script type="text/javascript">
var markers=[];
    var locations = [

    ['Corporate 3 DesignThis is where I work. i work with great people.', 41.249412, -96.03073, 1],
    ['This is simply a testThis is the info', 41.252615, -96.1338, 2]
    ];
	var mapOptions = {
	zoom: 10,
	center: new google.maps.LatLng(41.22,-95.95),
	mapTypeId: google.maps.MapTypeId.ROADMAP
	};
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
    var infowindow = new google.maps.InfoWindow();
    var marker, i;
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
	
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i)); 
	markers.push(marker)
    }
	var markerCluster = new MarkerClusterer(map, markers);  
  </script>

Thank you for this! I was having the hardest time trying to decipher through the google documentation trying to figure out how they were passing variables but this makes a lot more sense now that I see it in use.

Also, thanks for the catch on the javascript type/text. Long day and I completely looked past it
dylanbaumannn is offline   Reply With Quote
Reply

Bookmarks

Tags
google maps, markerclusterer, undefined

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:33 PM.


Advertisement
Log in to turn off these ads.