Google Maps API Projects
Home · Demo Maps · Projects · Discussion Forums · Downloads · Developer Available · Google Search · Site SearchSeptember 07 2010 09:56
Navigation
Home
Demo Maps
Projects
Discussion Forums
Downloads
Useful Links
Developer Available
Contact Me
Privacy Policy
Search
Google Search
Site Search
Paypal Donate

Donations encourage developers such as myself to provide support for and develop new versions of our code.

ClusterMarker: Guide

Guide

This guide assumes that you are reasonably familiar with creating a basic map using the Google Maps API. If you are a complete beginner then please try some of the online tutorials to familiarise yourself with the API. You can find links to tutorials on the Useful Links page.

Example:

Create a new map, an array of markers and a ClusterMarker.
The map will be contained by a DIV element with an id of 'map'.

var map=new GMap2(document.getElementById('map'));
map.setCenter(new GLatLng(0, 0), 0, G_NORMAL_MAP);

var marker, markersArray=[];

// (Entire example json data can be found here here.)

for (var i=0; i<json.length; i++) {
marker=newMarker(new GLatLng(json[i].lat, json[i].lng), json[i].id);
markersArray.push(marker);
}

var cluster=new ClusterMarker(map, { markers:markersArray } );
cluster.fitMapToMarkers();

function newMarker(markerLocation, markerId) {
var marker=new GMarker(markerLocation, {title:'Marker['+markerId+']'});
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml('<p>Marker['+markerId+'] clicked.</p>');
});
return marker;
}

This will create a map, an array of markers, and a ClusterMarker and then finally draw the markers on to your map.

To create a ClusterMarker you must pass it one argument: a reference to your map.
To see full details about optional arguments that can be used to create ClusterMarker please visit the Reference page.

To see this example in action please visit the Example Map page.

The full source code for the example map can be found here.


ClusterMarker: Index

Posted by martin on July 24 2008 13:15:38 15353 Reads · Print
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Users Online
Guests Online: 3
No Members Online

Registered Members: 237
Newest Member: Xavi
Google Maps API Projects © Martin Pearman 2010