1. Home
  2. Computing & Technology
  3. JavaScript

Google Maps

Allowing Visitors to Move and Zoom the Map

We can give our visitors the ability to interact with a Google map by adding controls to the map that they can use to request changes to what the map shows. As Google have already built these controls for us it is extremely easy to add them to our map because all we need to do is to add one line to our code in order to add a predefined control to the map.

The first of the controls that we may want to add to our map is one to allow our visitors to move the map around and to zoom the map in and out. This will assist them in working out just exactly where it is that your map is showing relative to places that they already know. We can do this just by adding the following line into our Google map code:

map.addControl(new GSmallMapControl());

Google also offer a momewhat larger version of the same control that you could add to your pap instead that will give your visitors a much better idea of what they have the zoom set to. To add that control instead of the smaller one you replace the above statement with this one:

map.addControl(new GLargeMapControl());

Here's what my map looks like with the smaller of these controls added to it.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.