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 7 ■ INFOWINDOW TIPS AND TRICKS<br />

};<br />

})();<br />

});<br />

var overviewOpts = {<br />

zoom: 14,<br />

center: marker.getPosition(),<br />

mapTypeId: map.getMapTypeId(),<br />

disableDefaultUI: true<br />

};<br />

var detailMap = new google.maps.Map(detailDiv, overviewOpts);<br />

// Create a marker that will show in the detail map<br />

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

position: marker.getPosition(),<br />

map: detailMap,<br />

clickable: false<br />

});<br />

// Check to see if an InfoWindow already exists<br />

if (!infoWindow) {<br />

infoWindow = new google.maps.InfoWindow();<br />

}<br />

// Setting the content of the InfoWindow to the detail map<br />

infoWindow.setContent(detailDiv);<br />

// Opening the InfoWindow<br />

infoWindow.open(map, marker);<br />

Creating a Zoom-In Link<br />

Sometimes you can provide users with shortcuts to make the user experience more pleasurable. One<br />

simple shortcut is to provide a zoom-in link in the InfoWindow. This way, the user can easily zoom in on<br />

an object without having to use the zoom controls.<br />

In this example, you will use the marker centered on Manhattan. Initially the map is zoomed out so<br />

all the United States is visible. When the zoom-in link in the InfoWindow is clicked, the map zooms in on<br />

the marker. See Figure 7-8.<br />

150

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

Saved successfully!

Ooh no, something went wrong!