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 5 ■ X MARKS THE SPOT<br />

This little snippet of code will put a marker on the map. It has the look of the default <strong>Google</strong> <strong>Maps</strong><br />

marker, and you can’t do anything with it really, but it dutifully marks a spot on the map, as shown in<br />

Figure 5-3.<br />

Figure 5-3. A simple marker<br />

Adding a Tooltip<br />

The first thing you might want to do is to add a tooltip to the marker. A tooltip is a yellow box with some<br />

text in it that appears when you hold the mouse pointer over an object. To add a tooltip to a marker,<br />

you’ll use the property title. It’s as simple as setting the title property of the MarkerOptions object<br />

(Listing 5-3).<br />

Listing 5-3. Adding a Title to the Marker<br />

// Adding a marker to the map<br />

var marker = new google.maps.Marker({<br />

position: new google.maps.LatLng(40.7257, -74.0047),<br />

map: map,<br />

title: 'Click me'<br />

});<br />

Doing this will add a nice little tooltip to the marker when you hold the mouse pointer over it, as<br />

shown in Figure 5-4.<br />

75

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

Saved successfully!

Ooh no, something went wrong!