27.10.2014 Views

Google Maps API 3

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9 ■ DEALING WITH MASSIVE NUMBERS OF MARKERS<br />

Figure 9-6. These two markers will not be clustered since they reside in different squares of the grid<br />

Distance-Based Clustering<br />

This technique looks at each individual marker and checks whether it’s nearby other markers. If it’s<br />

close enough to another marker, the two of them will be grouped into a cluster.<br />

Distance-based clustering also has its drawbacks. Since the clusters will appear at random<br />

locations depending on where a cluster is formed they may not make sense for the user.<br />

Regional Clustering<br />

A third technique is regional clustering. What this means is that you define different geographical<br />

regions, such as counties or states. All markers in each region will be grouped into a cluster. You also<br />

define at which zoom level the cluster will break up into separate markers (or smaller clusters).<br />

The advantage of this technique is that you can create clusters that make more sense to the<br />

user. The drawback is that it requires more effort and can’t as easily be automated as the other<br />

clustering techniques.<br />

Some Practical Examples<br />

We will soon take a look at some solutions for dealing with too many markers. But before you do that,<br />

you will create a map that features a lot of markers so that you have a problem to fix. Therefore, you<br />

will write some code that will auto generate markers at random locations.<br />

182

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!