Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 7 — Extending the Google API Examples 113


FIGURE7-5: Adding a simple marker.


Listing 7-5:Adding Markers from Points

function movemap(x,y) {
var point = new GPoint(parseFloat(x),parseFloat(y));
map.recenterOrPanToLatLng(point);
map.addOverlay(new GMarker(point));
}


In this case, each time the user clicks the restaurant link, an appropriate marker will be added.
Existing markers are not removed. Figure 7-6 shows the application after the user has clicked
two links.


Another alternative is to change the onLoad()code and create multiple markers when the
web page is first loaded, as shown in Listing 7-6.

Free download pdf