Simple Instructions for Google Map on Web Page

February 16th, 2007 Leave a comment Go to comments

So you want to embed an interactive Google Map on your web page? Here are the basic steps/instructions to do so.

1) Go to the Google Maps API page and request a free API Key. You’ll get the key and some sample code. It’s good for all pages under one domain. Keep this open and/or save the page content.

2) Open the HTML page for the map, and copy the linked JavaScript from the sample code into the document head. This is the first SCRIPT tag.

3) Copy the load() function from the sample code into the HTML page or into an externally linked JavaScript file. This is in the second SCRIPT tag.

4) Call the load() function in the body onload event, and the GUnload() function in the body unload event.

5) Replace the longitude and latitude values in the load() function with the values of your location on your map (these are the two numbers after “GLatLng”). You can find the longitude and latitude of your location. Here are some sites to help with this:

  • GeoCoder
  • Maporama
  • Find the location in Google Maps, the run this code from the browser’s location bar (paste and hit Enter or Go): javascript:void(prompt(”,gApplication.getMap().getCenter()));

6) One way or another, be sure to have alternative content (such as a static map) when JavaScript is not available on the client side (browser). A popular method is the NOSCRIPT tag.

You’re done! check out this Google Map example on this salon web site that I did. Go to the Google Map documentation for more details.

  1. February 19th, 2007 at 06:56 | #1

    Thank you very much for your simple instructions here. I have a basic map working on my prototype site – but just noticed the Google Javascript killed my Nifty Corners script and the 4 corners of my canvas are no longer round. Is there a smart way to combine Javascripts on a single page?

    Thank you.
    Liz M

  2. February 23rd, 2007 at 14:44 | #2

    Liz, sounds like you may have conflicting onLoad events (calling it twice). If so, try calling them from one onLoad function; best to use the addLoadEvent function. Good luck and have fun!

  3. February 25th, 2007 at 21:45 | #3

    Hi Dennis,

    Great article. I have implemented the map, but am having trouble understanding how to place the little red marker over the actual address, like you did on the Salon website. Can you give me an idea how to do that? Thanks,

    Dave Z.

  4. February 26th, 2007 at 23:35 | #4

    David, I used a function called “openInfoWindowHtml”. There’s great help in the Google Map documentation link at the end of the post. On that page, go to the section Display Info Windows Above Markers.

  5. MerMer
    June 26th, 2007 at 08:08 | #5

    I’m having the same problem as Liz. In IE6 Nifty Corners fails to work once I add the following:-

    It works fine in FFox. With IE I get an “Error: Object Expected”.

  1. February 21st, 2007 at 13:40 | #1