Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 7 — Extending the Google API Examples 125


FIGURE7-12: Synchronizing map display using listeners and events.


The example also shows two other key elements:


1.You can determine the current center point of your map by using the
getCenterLatLng()method on the map object. You can also determine the map
size, the span of the map (the span of the latitude and longitude being displayed), and
the bounds (edges) of the displayed map.

2.The example demonstrates how to adjust your map display type. Remember that you can
choose between three types (map, satellite, and hybrid) and that you can change the map
type at any time. You can also, by adding movement controls to your map, allow users to
choose the type of map that is displayed.

Adding Markers to Multiple Maps


Of course, if you have two maps like those shown in Listing 7-10, you might also want to
display the same overlays and markers. This is where the use of objects to store your overlay
items is useful. To add a marker to both maps, all you have to do is call the addOverlay()
method on each displayed map object. Listing 7-11 gives you an example of this by merging
the code from Listing 7-9 and Listing 7-10 to provide two maps with marker and information
windows.

Free download pdf