Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 9 — Using Overlays 161


printf(‘<marker lat=”%f” lng=”%f” title=”%s”/>’,
$row->{lat},
$row->{lng},
$row->{title});

}
$sth->finish();

print(“</marker>\n”);

Now that the information is located within a database, further restaurants can be added to the
map by adding rows to the database. There could be a potentially unlimited number of restau-
rants in the database, and the method in which the database is updated (from another web
interface or desktop application, or even a feed from another database or application) becomes
immaterial. The source does not matter.

What does matter is that the basic script and HTML page that was developed to display a
map of restaurants in a particular location has not changed. Only the source of information
driving the data displayed on the map has changed.

A sample of the map using information loaded from a database through the script in Listing 9-9
is available online at http://maps.mcslp.com/examples/ch09-09.html.

Extending the Information Pane


Back in Chapter 7, a logical extension of the basic map marker was to add an information win-
dow to the marker when the user clicks the marker. The idea of the information pane is to
show relevant information for a map point.

There are many ways of populating the pane with information, but the most practical, because
the map is now being built up using an XML source, is to continue using XML to generate the
content. This will require changes to the database to store more information such as the
address and phone number of the restaurant.

The HTML that generates the map will also need to be adapted so that the map marker and
information window are displayed when the user clicks the marker.

Formatting Information Panes.


As shown in Chapter 7, an information pane is added to a marker by adding an event listener
to the marker that triggers one of the openInfoWindow*()functions to create an informa-
tion window. The addmarker()function within the JavaScript in the HTML can be modi-
fied so that it adds the necessary event listener at the time when the marker is generated.

Listing 9-10 contains such a modification. Obviously, how the information is loaded that gen-
erates this information has not changed; the same principles can be used with either the static
or dynamic samples. For the moment, it is the information window trigger that is interesting.
Free download pdf