HOW TO: Embedded Google Maps

December 4, 2005 · 66 comments

It seems like someone releases another cool use for Google Maps every week. You have likely seen the ever popular Frappr service, based off of Google Maps. After Google Released the API for their popular Google Maps service, integrating maps into your site could never be easier. This article shows you how to embed a customized Google Map into your website or blog.



Before you do anything, as with most API-based web services, you will need to attain an API key before you are able to use the service. Head over to this Google Maps page to sign up for an API key. Signing up is pain free and you get the API-key right after you click on Generate API Key.


You then need to download the gmapez.js file from this website and host it somewhere on your website. The actual code necessary to make the map appear on your blog entry or website relies on using an iframe, so you will need to make another html file that the iframe will read from.


Below is the code you will need to put in that html file; a few things will need to be changed so keep on reading.



<!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>
<script src="http://maps.google.com/maps?file=api&v=1&key=YOUR_GOOGLE_MAPS_API_KEY_HERE" type="text/javascript"></script>
<script src="http://www.YOURDOMAIN.com/path/to/gmapez.js"
type="text/javascript"></script>
</head>
<body>
<div class="GMapEZ GLargeMapControl GMapTypeControl GScaleControl"
style="width: 400px; height: 400px;">
<a href="YOURGOOGLELINK">
</a>
</div>
</body>
</html>


This is the basic skeleton of code needed to get a Google Map running on your site. You will have to give it your Google API key as well as a valid url to your gmapez.js file. One more thing is the actual Google Maps link for the area you want shown on the map. Go to maps.google.com and find the location you want to be shown, double click on it and then copy the link via the Link to this page at the top right of the Google Maps site. Paste that url in the code above where it says YOURGOOGLELINK. This will automatically center the map on a marker of that location. You can create new markers my creating more and more <a href></a> type tags. Placing a capital letter between those tags will display that letter as the marker instead of the default dot. You can find out more about various configurations at the GMap EZ site.


Now to actually placing the code on your site. The piece below goes on the actual blog post or website page. Make sure to feed it the proper URL to your html containing the code above.



<iframe src="http://www.YOURDOMAIN.com/pathto/YOURCODE.html" width="500" height="500"></iframe>

Adding Info Bubbles

So you’ve got the gist of this Google Maps thing down, now lets add some spice and kick it up a notch. The next thing you can do is add an info bubble to your markers. This can easily be done by adding a div tag containing the information you want displayed right after the appropriate <a> tags (all within the main div that has the GMapEZ class) . You can even add images just as you would in any other html file. Below is the one I used in my example.



<div><img align="right" src="http://www.paulstamatiou.com/wp-images/paul.jpg"/>
My Dorm at Georgia Tech</div>


Specifying Default Map Type

Whenever your page containing the Google Map is loaded, you can determine what view the user will get. Go into the html file you created and find the first div tag section; it is right after the body tag. All you need to do is add one of the following tags where it says class=”GMapEZ GLargeMapControl GMapTypeControl GScaleControl”.


These are the tags you can use: G_MAP_TYPE, G_SATELLITE_TYPE, G_HYBRID_TYPE. The first displays the most common map view, then satellite view and finally hybrid, which displays a map over satellite view.

For example the code in your html should look like this after you’ve added a tag.



<div class="GMapEZ GLargeMapControl GMapTypeControl GScaleControl"
style="width: 500px; height: 500px;">
<a href="YOURGOOGLELINK">
</a>
</div>


Different Map Controls

The map I display at the bottom of this post uses large map controls, but you also have the option of small and mini controls. To use small controls change the div class to class=”GMapEZ GSmallMapControl” instead of the current value of class=”GMapEZ GLargeMapControl GMapTypeControl GScaleControl”. Mini controls can be set with class=”GMapEZ GSmallZoomControl GSmallMapTypeControl”.


Auto Open Marker Info

You can have the information for a marker automatically open when the map is loaded (opposed to it opening when it is clicked) by placing OPEN within the <a> tags for that marker.



If you want to see what the html for a completed map, such as mine, looks like just take a gander at the source code for this page. Also, any questions can be sent to me here or via the comments below. I encourage commenting as someone else might have the same question.

It seems the embedded map stopped working. I wrote this a long time ago and haven’t had the chance to look through it yet. I think it might have something to do with Google’s updated API.

PaulStamatiou.com runs on the Thesis Theme for WordPress

How smart is your Theme?  How good is your support? Check out ThesisTheme for WordPress.

Thesis is the search engine optimized WordPress theme of choice for serious online publishers. If you’re a blogger who doesn’t understand a lot of PHP, Thesis will give a ton of functionality without having to alter any code. For the advanced, Thesis has incredible customization possibilities via Thesis hooks.

With so many design options, you can use the template over and over and never have it look like the same site. The theme is robust and flexible enough not only to accommodate a site like PaulStamatiou.com, but also to enable the site to run far more efficiently than it ever has before.

{ 22 trackbacks }

So you want to add a Google Map to your site? - Brokekid.net
December 5, 2005 at 6:16 pm
Ian Scott » Blog Archive » Add Google Maps To Your Website
December 6, 2005 at 12:48 am
William’s Scratch Book » HOW TO: Embedded Google Maps
December 6, 2005 at 3:45 am
arde en el infierno » GoogleMaps OWZ!!
December 6, 2005 at 12:03 pm
stuart @ amanzi - Stuart Maxwell’s blog with news, articles, links and more » Blog Archive » links for 2005-12-07
December 7, 2005 at 2:46 pm
Where do the Simpsons live? at MaxPower
January 12, 2006 at 2:10 am
Shanafelt Sector
January 13, 2006 at 8:32 am
Add Google Maps to your Website - BethesdaWebSolutions.com
January 14, 2006 at 6:23 pm
pinanti is pinanti » Blog Archive » links for 2005-12-06
February 3, 2006 at 1:17 pm
ŠCŠOƒlƒbƒgƒrƒWƒlƒXî•ñ
February 12, 2006 at 12:31 am
the evangelical outpost
February 15, 2006 at 1:49 am
Riku’s blog » links for 2006-06-04
June 4, 2006 at 4:18 am
found_drama » Blog Archive » links for 2006-10-03
October 2, 2006 at 8:44 pm
links for 2006-10-16
October 16, 2006 at 6:20 pm
moT Blog » Blog Archive » Je eigen Google
October 20, 2006 at 7:27 am
moT Blog » Blog Archive » Je eigen Google
October 20, 2006 at 7:43 am
moT Blog » Berichten » Je eigen Google
November 13, 2006 at 7:17 am
links for 2007-04-15 » a big guy in a big city
April 15, 2007 at 4:20 pm
Joao.Rico » Blog Archives » how to embedded google maps
June 9, 2007 at 7:56 pm
OpenJason » Blog Archive » 666 Tools, Utilities, and … tools, utilities..
September 22, 2007 at 1:22 am
google » HOW TO: Embedded Google Maps - PaulStamatiou.com
October 6, 2007 at 2:49 pm
mp3 ringtones converter
January 8, 2008 at 12:46 pm

{ 44 comments… read them below or add one }

1 Joe December 4, 2005 at 1:07 pm

Hi,

Great intro! I noticed that the text in the InfoWindows seems to be wrapping unexpectedly instead of going the whole width of the InfoWindow. Is there a setting or technique to get the text to display correctly?

Thanks.

Reply

2 Paul Stamatiou December 4, 2005 at 1:26 pm

Joe: That one is still a mystery to me.

Reply

3 R.I.Pienaar December 5, 2005 at 5:03 pm

I wrote a wrapper around GMapsEZ that will take a XML file and output a map thats easy to embed as well, using this you can create maps with loads of points by just editing the XML:

http://www.devco.net/pubwiki/GMapsPHP

Reply

4 Paul Stamatiou December 5, 2005 at 5:11 pm

Awesome! Thanks for letting us know.

Reply

5 Mortimer December 5, 2005 at 7:37 pm

You could also use XMaps (http://xmaps.busmonster.com/documentation.html) there is a bit more javascript to do, but it is huge, you can draw almost anything on the map, not only these markers (see the link on my name for a “beta” example).

Joe, you can put whatever you want in that div for the InfoWindows, almost any html will go. So you can put a span or another div with css style you need. Look at BeenMapped (http://www.beenmapped.com/) for example of what you can do with InfoWindows.

Reply

6 Justin Johnson December 5, 2005 at 8:02 pm

I’ve written a PHP class called Phoogle Maps that does basically the same thing that this javascript library does. I’ll give the link as an alternative to your method of doing things: http://www.system7designs.com/codebase

Asfar as text wrapping in the div I think you have to give it a clear in the divs CSS, I found the answer to this at one point, I’ll have to dig around and see if I can find it

Reply

7 Brandon December 5, 2005 at 11:27 pm

Hey, your site! Its yellow!

Cool write up too. Very helpful. But get ready for some stalkers now that they know where you live.

Reply

8 Adam Teece December 6, 2005 at 1:39 am

Hey I like the new colors of your site. I might have to see about putting Google Maps somewhere on my site, which is alot better now. Thanks for the great tips Paul.

Reply

9 Paul B December 6, 2005 at 3:14 am

Hi! Great article, I’m so glad I found your site! I read this article this afternoon and started implementing it right away on my bands website. Click here to go to the site, then click on the tourdates button on the left…

I think the issue with the text wrapping in the DIV was related to firefox… it looked fine when I tested it in IE. I fixed it on my site by making a 1X1 table with a width of 200 pixels inside each DIV tag containing the InfoWindow content. This might not be the “right” way to fix it, but it seems to have worked nonetheless.

Thanks again, and I’m looking forward to future articles!

Reply

10 cypher December 6, 2005 at 3:30 am

I’ve been playing with GoogleMaps lately [http://paragliding.cotasson.info/].
To avoid text-wrapping you have to set a minimum width attribute within a DIV element
(see HTML source).

HTH.

Reply

11 neo December 6, 2005 at 6:24 am

Hi everybody, does anybody knows what’s happening with Flickr, check out any Flickr Flash Slideshow or Flickr badge with Internet Explorer and that does not show up, I’m pop up a page not available message. So does anybody know what’s happening.

Reply

12 Paul Stamatiou December 6, 2005 at 10:35 am

Paul B: Glad you could make use of my tutorial. I love your implementation and styling of the info bubbles!

Reply

13 John Henry December 6, 2005 at 3:25 pm

Here’s an interesting question…I’m setting this thing up (and thanks for the GREAT tutorial as well as the other contributors’ notes!) and it looks pretty decent so far (here), but as you can see (unless I get this figured out before you look) the color of the info balloon doesn’t match my site design.

Obviously this is a minor issue that can go without correction, but does anyone know how to change the color of the surrounding ballon and structures (border and close button)? That would make this the closest thing to a perfect new design tool since the invention of Dreamweaver…

Reply

14 james24 December 13, 2005 at 3:04 pm

Here’s a cool blog with tons of people ideas for maps they created.

http://www.coolgooglemaps.com

Reply

15 None February 13, 2006 at 5:07 am

Just wanted to see the cool effect, sorry.

Reply

16 M Hess March 22, 2006 at 12:57 am

I am trying to get a question answered, and thought you could help. I’m creating a Google map and find that in IE 6, the info windows display perfectly when the marker is clicked. Ditto for Firefox 1.5. However, in Firefox 1.0.7, the text does not wrap within the window — just runs in a straight line out the window and off the map.

To see my test map, you can go to http://www.geocities.com/Athens/4209/maps/gmapexmple4.htm

Do you have any ideas how I can fix this? I know it is possible, and someone suggested using a tag in a thread I found, but I’m not sure how this would work, especially since I’m just figuring out how to use xml and xsl for my map’s information and styling.

Reply

17 Mark Argentino April 6, 2006 at 12:27 am

I have been using gmapsez for some time and it’s been a great feature that many of my clients like.

Now that Version 2 has come out, I’ve read as much as I can at Google Maps API Version 2 documentation, but since I am using maps EZ, I cannot seem to get the new version to work at all.

Do you know where I can get help with gMapEZ for google maps api version 2 ?

It really was so easy to install and get this program to work and now I am just totally confused and cannot get the new version to work.

One of my maps is at this link, but this is for version 1 http://www.mississauga4sale.com/listings-google-maps.htm

Please, can you tell me what I am missing here in the big picture? I love google maps function and don’t want to lose it’s use.

Do I have to start from scratch and learn all about the new documentation?

Any help would be appreciated.

Thank you,
Mark

Reply

18 c. wess daniels April 13, 2006 at 5:48 pm

hey paul – is it too early to be able to put the google calendar on our WP blogs? Or do you know any secrets? Oh and I enjoyed your podcast on 101 the other day!

Reply

19 Charlie July 4, 2006 at 2:19 pm

great howto!

Reply

20 mike July 7, 2006 at 2:06 pm

great tutorial. thanks a lot. question, what do you have your tag font set as? the drop a comment like its hot doesn’t look like the usual sans-serif. mscopino@biblio.org if you ever have time to answer that. thanks again.

Reply

21 mike July 11, 2006 at 7:42 am

paul

thanks for that response last night. i went to the gmapez site looking for an answer.

what i found was this:

you say use this in the head of your document for the api key:

they say use this:

seems to have worked.

thanks again

Reply

22 Alex July 27, 2006 at 3:33 am

How do you center the map on the page once it is completed?

I need help with this. It just won’t let me move it at all. is there a piece of code I can add to it to center it? Thanks guys.

Reply

23 Jonathan July 28, 2006 at 1:20 am

I built a tour of our entire trip inside of Google Earth. Is there a way to export it out into a map that I can display on my site, instead of building the trip all over again, URL by URL?

Any help greatly appreciated!

Reply

24 adwait August 8, 2006 at 7:15 am

I want the html codes for the small google search thingy (just like the google homepage but only smaller in size.) on the sidebar of my blog. Please mail it to me. If ya got some more of these plzzz contribute them.
thank you.

Reply

25 Paul Johnson October 23, 2006 at 10:55 am

Hi

We’ve created a tool that allows you to create customised maps with Google Maps that you can embed in your website quickly and easily. You can add overlays with further information, too, if you wish. If it sounds of interest, take a peek at http://www.aardvarkmap.net

Good luck everyone…

Paul

Reply

26 Mark Argentino of Mississauga Homes for Sale December 5, 2006 at 10:06 am

Hi Paul,

This is a very helpful post you have provided herein. You make reference to ‘the map you display at the bottom of this post’ and yet I cannot find your map.

Can you send me the url of your google map using GMapEZ such as the one I am using at http://www.mississauga4sale.com/listings-google-maps.htm so I can compare the two?

Thanks again for everything,
Mark

Reply

27 Vincent Glennon December 22, 2006 at 9:10 am

Hi all,

I have just launched a website that is like TinyUrl.com but for maps. You can embed maps onto your website, get detailed Travel Directions from/to most places, call the map anything you like,etc. As it is also free, you can take a good look at it at http://useamap.com . The full feature list is available here:http://blog.useamap.com/?p=21

Thanks.
Vincent Glennon
Ireland

Reply

28 o January 5, 2007 at 10:33 pm

Hello,

Does anyone know how to get the map embedded on a site to start in hybrid mode? Thanks!

O.

Reply

29 Vincent Glennon January 6, 2007 at 9:18 am

Hi,
In reply to an above comment, you can create an embedded map that loads in hybrid mode quickly on http://useamap.com . Simply find your location in hybrid mode on the map and save it. Then click on embed map. You will be given code to embed the map onto your site, and your site will now load a hybrid mode map of your location every time. You can also quickly change it to another map type by changing the map settings within useamap.com
Best regards,
Vinny Glennon

Reply

30 Vincent Glennon January 10, 2007 at 3:12 pm

Hi,
An above comment asked how to embed a map to start in hydrid mode. This is very easy with Useamap.com to do. Just create a map in your desired mode, grab the embed code, and put onto your website. Simple and quick.
Vinny

Reply

31 manicdrone April 16, 2007 at 12:00 am

Nice, but a little complicated maybe. Ongopongo.com has a tool to embed Google My Maps and it’s a bit simpler. You can also share your maps and other stuff.

Reply

32 Carl Chapman May 12, 2007 at 1:04 pm

Dang, I jsut found this post today (5-12-2007) and it is EXACTLY what I need, but the site with the gmapez.js file is down.

Paul, I’m in Atlanta and a Tech fan even though my duaghter is at UGA. Thanks for the post. Hopefully someone can tell me where I might get the javascript file.

My email addy is easily locatable on my website under Contact Us.

Reply

33 motherduce September 10, 2007 at 10:12 pm

Paul – thought about updating this with the new embed feature from Google? Unfortunately, it uses iFrames, so it’s not valid code. Wondering if you know of a workaround yet.

Cheers,
Duce

Reply

34 Paul Stamatiou September 10, 2007 at 11:20 pm

@motherduce – thanks for reminding me, I’ve been meaning to update this post. I’ll look into it and report back.

Reply

35 motherduce September 11, 2007 at 10:34 am

Cool, thanks Paul.

Reply

36 Rupinder September 21, 2007 at 5:07 pm

I am implementing google maps and markers. When I click a marker, details about that marker are shown in an info window along with a short map showing that marker only. All the info is showing fine but the map does not show.

Also when the infowindow is displayed, all the links and fonts on other parts of the page are affected and changed which is weird.

I would really appreciate if you could offer some help.

Reply

37 kim July 20, 2008 at 7:34 am

Good headstart for implementing the code, api has changed tho

Reply

38 John August 24, 2008 at 1:17 pm

Paul, I’m a novice using Front Page (I know, I know, I’m not a fan of anything ‘MS’ either, I’ll get better.). Any idea why the google map code keeps crashing my Front Page session and causing it to ’send error report’ then reboot Front Page?

Is it something I’m doing wrong or just stock standard typical Mr Gates & co?

I’ve put an inline frame in the draft web page. I put the code in as you’ve advised above. I’ve aquired an API key and followed the instructions. I’ve tried just a simple link to the map. In all cases it crashes FP on me whilst trying to obtain the map.

Any ideas?

Thanks in advance.
J.

Reply

39 pepito perez September 6, 2008 at 12:49 pm

deja de ser gueva…..este tutorial no sirve…..incluiste toda la pagina

Reply

40 Alan Wilkinson September 8, 2008 at 12:45 am

There seems to be a strange sort order on these comments. Is the Date Sort format screwed up?

I have the same problem as John (24 Aug 08). Frontpage 2002 crashes when a Google map is inserted in the page which is then viewed in Normal mode.

In Preview mode it shows a “script error” but doesn’t crash. The page works fine in IE7 in either preview mode or when published.

Reply

41 Andreas November 18, 2008 at 6:24 pm

Hi there!

I need to get into place a function where a person visiting one of my websites, enters information, like an street address, I want that data to be saved in my database and when another website visitor clicks that link for the added address, it should bring up the GoogleMAP and show the visitor that specific address.

So, what am I actually after?
Well, a “dynamic” function where GoogleMAP shows the location on a GoogleMAP based on streetaddress data fetched from ie my database.

Is it possible? If so – HOW do I do it?

Thank you in advance for support!

–Andreas

Reply

42 abhishek December 5, 2008 at 7:42 am

good information……..Thanks……

Reply

43 Sam February 12, 2009 at 5:44 am

Hey guys… this is a really active forum… I have a question.
Can the content from the bottom you know, the text that appear before the TERMS OF USE be contained inside the DIV… It just goes all the way to the left outside the DIV and it looks uncool.

Anny comments are greatly appreciated.

Reply

44 aou January 25, 2010 at 11:13 pm

Now you can add a traffic layer to your google map with two lines of JS code:
trafficInfo = new GTrafficOverlay(trafficOptions);
map.addOverlay(trafficInfo);

See sample traffic map for Toronto.

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: