27.10.2014 Views

Google Maps API 3

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Creating the Markers<br />

The next step is to create all of the markers. You’ll start by creating an array that will contain<br />

them. Let’s call the array markers.<br />

var mgr = new MarkerManager(map);<br />

var markers = [];<br />

You will use the same code as in the two previous examples for creating random markers but<br />

change it a little bit. Instead of creating markers inside the current viewport, you’ll define the<br />

boundaries within which the markers will be created as a square covering most of the United States.<br />

Since you already know the boundaries, you don’t have to listen for the maps bounds_changed event but<br />

can go straight to defining the boundaries and creating the markers (Figure 9-11).<br />

var mgr = new MarkerManager(map);<br />

var markers = [];<br />

var southWest = new google.maps.LatLng(24, -126);<br />

var northEast = new google.maps.LatLng(50, -60);<br />

var lngSpan = northEast.lng() - southWest.lng();<br />

var latSpan = northEast.lat() - southWest.lat();<br />

Figure 9-11. The markers will be created within these boundaries covering most of the United States.<br />

197

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

Saved successfully!

Ooh no, something went wrong!