learn web technologies, the easy way

You’ve seen how to create a Google map. You may have noticed that the code has always included both Javascript and HTML. This is all that is required in order to display a static map, i.e. one that always displays the same markers (or no markers). To review the way to create a map with multiple (static) markers see Multiple Map Markers.

Unless your only purpose in creating one (or few) markers to indicate where your company headquarters, restaurant or club is located, you'll need to start using dynamic markers. So let's get started!

Write Maps JavaScript from PHP

Instead of hard-coding the markers as we've done until now, we'll retrieve the data from a source outside your page and write/create the map Javascript code, which specify the markers, using a dynamic language such as PHP or ASP. We’ll be using PHP, as that is our language of choice. In this lesson you'll see how do use a database as your data source.

NOTE: The language availble to you may be dictated by your Internet host. However, if you’re lucky enough to be the owner of the server, then you'll be able to install whatever dynamic language you please. As long as the language has the features we demonstrate here, you’ll be all set to create dynamic maps.

Dynamic Code means Less Code

Huh, I thought it would be more difficult and take more coding?

It is true that a map with only a few markers would take less code than using a dynamic method, but it is a fact the size of static code expands with every new marker whereas the size of dynamic code always stays the same.

On the next page, we show how to create the map code dynamically. And while it is about the same length as the last listing, it will never get longer due to additional markers, it will just produce as many markers as there are in the database, cool huh?