Find your B&B / Inn
  By Keywords   By Map   By Distance 
Search by Keywords or BB / Inn Name
Whole Word only Case Sensitive
Sort: Per Page:
ExpandSmoking: No preference
ExpandHandicapped Accessible: No preference
ExpandPets Allowed: No preference
ExpandInternet/Wireless: No preference
ExpandSoft Adventures: No preference
ExpandActive Adventures: No preference
ExpandRomance and Relaxation: No preference
ExpandInside Activities: No preference
ExpandFishing Adventures: No preference
ExpandWater Adventures: No preference
Reservation Enquiry Cart
Compare List
Information Centre

 

Home > Resources > Programming Tutorials > Add Google Map to your site

The "Hello, World" of Google Maps

The easiest way to start learning about this API is to see a simple example. The following web page displays a 500x300 map centered on Palo Alto, California:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src=http://maps.google.com/maps?file=api&v=2&key=abcdefg
            type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
      }
    }

    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>
  </body>
</html>

You can copy/paste the entire source code above to edit and play around with it, but you'll have to replace the key in that file with your own Maps API key. (If you register a key for a particular directory, it works for all subdirectories as well.)

The URL in the example above (http://maps.google.com/maps?file=api&v=2) is the location of a JavaScript file that includes all of the symbols you need for placing Google Maps on your pages. Your page must contain a script tag pointing to that URL, using the key you got when you signed up for the API. If your Maps API key were "abcdefg", then your script tag might look like this:

<script src=http://maps.google.com/maps?file=api&v=2&key=abcdefg
        type="text/javascript">
</script>

The class that represents a map is GMap2. This class represents a single map on the page. You can create as many instances of this class as you want (one for each map on the page). When you create a new map instance, you specify a named element in the page (usually a div element) to contain the map. Unless you specify a size explicitly for the map, the map uses the size of the container to determine its size.

Send this page to your friend Contact Us About Us Add Listing Update Listing