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 8 ■ CREATING POLYLINES AND POLYGONS<br />

Figure 8-5. A dynamic polyline. Each click in the map adds a point to it.<br />

The Complete Code<br />

Listing 8-3 shows the complete code for this example:<br />

Listing 8-3. The Complete JavaScript Code for Example 8-2<br />

(function() {<br />

window.onload = function(){<br />

// Creating a map<br />

var options = {<br />

zoom: 5,<br />

center: new google.maps.LatLng(36.1834, -117.4960),<br />

mapTypeId: google.maps.MapTypeId.ROADMAP<br />

};<br />

var map = new google.maps.Map(document.getElementById('map'), options);<br />

// Creating an empty MVCArray<br />

var route = new google.maps.MVCArray();<br />

// Creating the Polyline object<br />

var polyline = new google.maps.Polyline({<br />

path: route,<br />

strokeColor: "#ff0000",<br />

strokeOpacity: 0.6,<br />

strokeWeight: 5<br />

165

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

Saved successfully!

Ooh no, something went wrong!