demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter.

featured articles

popular favourites

Map of the world, supplied by Google Maps

Web Multimedia: Embedding A Google Map

Google maps can be very useful to embed in eMail invitations or to address the locations of businesses on websites. Using "Link" at the top right of the Google Maps site generates the following, overly complicated code:

  1. <iframe width="425" height="350" frameborder="0" scrolling="no"
  2. marginheight="0" marginwidth="0" src="http://maps.google.com/maps?
  3. f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=SAIT&amp;sll=51.072439,
  4. -114.070699&amp;sspn=0.011325,0.019698&amp;ie=UTF8&amp;hq=SAIT
  5. &amp;hnear=&amp;ll=51.066852,-114.09263&amp;spn=0.011327,0.019698&amp;z=14
  6. &amp;iwloc=A&amp;cid=17534328178977113185&amp;output=embed"></iframe>
  7. <br /><small>
  8. <a href="http://maps.google.com/maps?
  9. f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=SAIT&amp;s
  10. ll=51.072439,-114.070699&amp;sspn=0.011325,0.019698&amp;ie=UTF8&amp;hq=SAI
  11. T&amp;hnear=&amp;ll=51.066852,-
  12. 114.09263&amp;spn=0.011327,0.019698&amp;z=14&amp;iwloc=A&amp;cid=175343
  13. 28178977113185" style="colour:#0000FF;text-align:left">
  14. View Larger Map</a></small>

There is also the issue that frames work for HTML4 and 5, but not XHTML: the equivalent in XHTML is the <object> tag. However, if you copy the src attribute value, the code can be simplified to:

  1. <object style=”width: 425px; height: 350px;" data="http://maps.google.com/maps?
  2. f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=SAIT&amp;sll=51.072439
  3. ,-114.070699&amp;sspn=0.011325,0.019698&amp;ie=UTF8&amp;hq=SAIT&amp;hnear
  4. =&amp;ll=51.066852,-114.09263&amp;spn=0.011327,0.019698&amp;z=14&amp;iwloc
  5. =A&amp;cid=17534328178977113185&output=embed">
  6. </object>

The result:

There are many, many tricks and hacks for Google Maps, which are the subject of several books. I will tell you that the ll variable values in the URL represent latitude and longitude, and z the amount of zoom.

Using this method will bring all the interactivity one associates with Google Maps into the map on your webpage: scrolling, zooming, etc. While that is wonderful, the interactive map takes some time to load. Sometimes, you simply need a fast image of your location. This is possible by using the Google Static Map API. The simplest required parameters for the API are shown in the URL below:

  1. http://maps.google.com/maps/api/staticmap?center=SAIT,AB&zoom=14&size=400x400
  2. &sensor=false

centre takes either an address (just as you would type into Google Maps) or latitude and longitude data, as used in the object tag above. zoom is the level of zoom, and size is the width and height of the image as presented on your page, up to 640 x 640. sensor is false on the assumption that there is no location awareness on the device you are sending the data to: if you were sending the static map to an iPhone or other device with location awareness, this could be switched to true.

Actually using the URL to produce an image is the simplest thing in the world – just put the URL as the src value in an img tag, remembering to replace & symbols with &amp; where necessary if you want the page to remain valid. For example, this:

  1. <img src=”http://maps.google.com/maps/api/staticmap?center=SAIT,
  2. %20AB&zoom=1&size=550x485&maptype=satellite&sensor=false" alt=”Map of the world
  3. supplied by Google Maps” title=”Map of the world, supplied by Google Maps” />

…produces the image you see above. Much more is possible, including routes, markers, and highlighted areas, and different formats for the image. For further information, consult the site for Google Map's API

You must be signed up in order to leave comments.

web developer guide

featured comment

by Aisling Brock in New Business Card Design

what i'm reading

A Feast for Crows: A Song of Ice and Fire: Book Four
A Feast for Crows: A Song of Ice and Fire: Book Four

what i'm watching

Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]
Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]

what i'm playing

Borderlands
Borderlands

what i'm hearing

Planets
Planets

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.