jQuery and Google Maps Tutorial: #1 Basics: jQuery, Google Maps

jQuery and Google Maps Tutorial: #1 Basics

Category: JavaScript & jQuery Tags: jQuery, Google Maps | Written on Mar 04, 2009

There are many times I want to leverage jQuery's strengths to create a custom Google Maps mashup. In this tutorial, I will walk you through how to get started using jQuery inside the Google Maps environment. I will assume nothing, and explain each piece in detail.

View Final Demo

If you are already familiar with Google Maps API, skip to step #5, or so.

Step #1: Get API key

First, grab yourself an API key for Google Maps, you will need this in the next step.

Step #2: Load Google Maps and jQuery

We want to load up jQuery and Google Maps with the Google AJAX Libraries API.

JavaScript:
  1. <script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_API_KEY_HERE">
  2. <script type="text/javascript" charset="utf-8">
  3.     google.load("maps", "2.x");
  4.     google.load("jquery", "1.3.1");
  5. </script>

Make sure to replace YOUR_API_KEY_HERE with your API key. By using the Google AJAX Libraries API, it allows you to load the JavaScript libraries you need right from Google's servers. This increases the chance that your users will be able to load the scripts faster from their browser cache, as well as shuffle the jQuery script loading off your server.

Step #3: Create the Google Map

Google Maps Basic

To create our Google Map, we need to create a container div and use CSS to give it a width and a height.

HTML:
  1. <div id="map"></div>
Css:
  1. <style media="screen" type="text/css">
  2.     #map { width:500px; height:500px; }
  3. </style>

Use the GMap2 function to make a map instance. Then, set the center of the map. I wrapped this code block in jQuery's document ready function so that the code is run after the page has loaded.

JavaScript:
  1. $(document).ready(function(){
  2.     var map = new GMap2(document.getElementById('map'));
  3.     var burnsvilleMN = new GLatLng(44.797916,-93.278046);
  4.     map.setCenter(burnsvilleMN, 8);
  5. });

Here, I used Burnsville, MN's latitude and longitude because it is where I live right now. There are many ways to get the latitude and longitude of an address, like this simple service by iTouchMap.

The second parameter for setCenter is the zoom level, which is a number. I set the zoom level to "8" here because it is about in the middle.

At this point we should have a simple map.

Step #4: Load the Google Maps Example

To have some points to work with, let's paste in the google maps example.

JavaScript:
  1. // setup 10 random points
  2. var bounds = map.getBounds();
  3. var southWest = bounds.getSouthWest();
  4. var northEast = bounds.getNorthEast();
  5. var lngSpan = northEast.lng() - southWest.lng();
  6. var latSpan = northEast.lat() - southWest.lat();
  7. var markers = [];
  8. for (var i = 0; i < 10; i++) {
  9.     var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
  10.         southWest.lng() + lngSpan * Math.random());
  11.     marker = new GMarker(point);
  12.     map.addOverlay(marker);
  13.     markers[i] = marker;
  14. }

Note that I added a markers array to the example code. This will be used in the next step.

Step #5: Loop Through Markers and Add Basic Click Event to Markers

In this step, we start to use jQuery and Google Maps together. We want to be careful to use Google Map's built-in API as much as possible, leaving jQuery only for what it is best at.

Let's take that array of markers and loop through them with jQuery's each method.

JavaScript:
  1. $(markers).each(function(i,marker){
  2.     GEvent.addListener(marker, "click", function(){
  3.         map.panTo(marker.getLatLng());
  4.     });
  5. });

Inside the loop, let's use Google Maps's GEvent namespace to attach a click event to each marker. Then, we will add a panTo behavior to center the map on the marker. marker.getLatLng(); returns the latitude and longitude of the marker, while map.panTo(GLatLng) allows us to center the map on that latitude and longitude.

Step #6 - Make a Clickable List of Markers

Let's add a clickable list next to the map. Insert a ul.

HTML:
  1. <ul id="list"></ul>

Then let's style it up a bit by floating the map left and float our list element next to it. We also want to add a hover effect to the list items to give visual feedback to the user that they can click on each item in the list.

Css:
  1. <style type="text/css" media="screen">
  2.     #map { float:left; width:500px; height:500px; }
  3.     #list { float:left; width:200px; background:#eee; list-style:none; padding:0; }
  4.     #list li { padding:10px; }
  5.     #list li:hover { background:#555; color:#fff; cursor:pointer; cursor:hand; }
  6. </style>

In our jQuery each loop from last step, let's append the clickable list items to the list.

JavaScript:
  1. $("<li />")
  2.     .html("Point "+i)
  3.     .click(function(){
  4.         map.panTo(marker.getLatLng()); 
  5.     })
  6.     .appendTo("#list");

Here I am just setting the content to "Point (the count)", adding that same panTo action from before, then appending the list item to our list.

Step #7 - Add a Custom Message

When I create a Google Maps mashup, I usually want to replace the built-in info window with something custom. With jQuery, we can add any arbitrary HTML in place of the info window. This is great when you want complete control over what the info window looks like.

Add a message div with some test text.

HTML:
  1. <div id="message" style="display:none;">
  2.     Test text.
  3. </div>

Then add some basic styling to the message.

Css:
  1. #message { position:absolute; padding:10px; background:#555; color:#fff; width:75px; }

We have to place the message div inside the map. To do this, we can use jQuery to append it to an object. The map view is seperated into panes. Each pane is a div layered on top of the other. To get the div object that we want to attach our message div to, we can use map.getPane(PANE). The G_MAP_FLOAT_SHADOW_PANE is the layer that I find works best for attaching custom messages.

JavaScript:
  1. $("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));

To show the message div in place of the info window, we need to separate the click action into a separate function. Replace the map.panTo(marker.getLatLng(); with displayPoint(marker, i);, a call to the new displayPoint function shown below.

JavaScript:
  1. function displayPoint(marker, i){
  2.     map.panTo(marker.getPoint());
  3.    
  4.     var markerOffset = map.fromLatLngToDivPixel(marker.getPoint());
  5.     $("#message").show().css({ top:markerOffset.y, left:markerOffset.x });
  6. }

We put the panTo action in our new function. Then the magic function here is the map.fromLatLngToDivPixel(GLatLng); which converts the latitude/longitude of the marker into a pixel on the map div.  This returns a  object containing x (amount of pixels from the left of the map) and y (amount of pixels from the top of the map).

Final Step #8 - Add Some Spice

To finish up, we will add an event when the map stops panning. We can do this by attaching the "movend" event map object. This way, after panning to the marker you've clicked on we can use jQuery's fadeIn method to add some spice.

JavaScript:
  1. function displayPoint(marker, index){
  2.     $("#message").hide();
  3.    
  4.     var moveEnd = GEvent.addListener(map, "moveend", function(){
  5.         var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
  6.         $("#message")
  7.             .fadeIn()
  8.             .css({ top:markerOffset.y, left:markerOffset.x });
  9.    
  10.         GEvent.removeListener(moveEnd);
  11.     });
  12.     map.panTo(marker.getLatLng());
  13. }

There you have it. We've come a long ways by adding our own custom click event, a clickable list and a custom info window. In the next tutorial, I'll show you how to store and retrieve points with a server-side language.

View Final Demo

Comments

#1. Ian Pitts http://iso-100.com on Mar 05, 2009
This is excellent! I had no idea it was this easy to integrate Google Maps into a site with such a minimum of code. Thanks for taking the time to write this up.
#2. Casey Becking http://www.caseybecking.com on Mar 05, 2009
Very nice and very descriptive just how a tutorial should be thank you!
#3. Andrew Collins http://www.dripsandcastle.com on Mar 05, 2009
I prefer code-centric and code-heavy how-to's, so thanks for the excellent tutorial.
#4. Keir Clarke http://googlemapsmania.blogspot.com/ on Mar 05, 2009
This is excellent. Can't wait for part 2!
#5. Holger Weis http://www.betawax.de/blog/ on Mar 06, 2009
Thanks for the nice tutorial!
I noticed that you use document.getElementById() in your example, but you can also do this via the jQuery $() function. This is how I solve this:
var map = new google.maps.Map2($("#map").get(0));
Don't forget to append the .get(0)!
#6. Marc Grabanski http://marcgrabanski.com on Mar 06, 2009
@Holger Weis: Thanks for letting people know jQuery's alternative to document.getElementById.
#7. Logan http://pihole.org/ on Mar 06, 2009
Excellent stuff! This will really come in handy. The only final step I would like to see is highlighting in the list when a marker is clicked.
#8. Mike http://www.mikescriber.com on Mar 10, 2009
Excellent Tutorial!

How would I go about having the map zoom in closer when a user clicks on a location? I've tried a bunch of things and nothing seems to work. It keeps the default zoom.

Thanks
#9. Marc Grabanski http://marcgrabanski.com on Mar 10, 2009
map.setZoom(number); sets the zoom of the map.
#10. Derek Tut on Mar 12, 2009
How can I animate the map so it now goes from point to point, pausing and popping up a balloon for each point as it goes along?
#11. Ben on Mar 17, 2009
And here is a tutorial for Google Maps made in paper :)
Pretty sure you'll like it.
http://www.youtube.com/watch?v=I9TtDecveCE
#12. Erik White http://erikwhite.net on Mar 17, 2009
Hi Marc, thanks for the tutorial! I've built upon your script and added a couple of new features.
You can see it in action at www.erikwhite.net/gmapjquery.html

Note: I haven't tested it in anything besides Firefox 3 yet so there could be some cross-browser issues

It now uses an array to store the locations which means you can add data such as labels and text for the markers. When the page loads, it cycles through the array and shows each array item in sequence. If you add more items to the array it will speed up so you don't have to sit and wait for too long. It also allows you to toggle markers which doesn't work in your version and shows an active state when you click on a marker or a list item.
#13. Sachin on Mar 23, 2009
I am a non- programmer. does anyone know about any ready made tool for same or similar requirement? it would be of gr8 help.
#14. Roberto on Mar 26, 2009
Can I add my own map to the API?
A picture, for example.
Thanks.
#15. Brandon http://ww.bpurcell.org on Mar 31, 2009
Sachin, if you are looking for a non technical solution SpatialKey provides some amazing maps and reporting without a line of code.
#16. Tim on Apr 04, 2009
What if you have duplicate coordinates that are the same; can you create one marker with multiple details in your custom description.
#17. Eric Rasch http://ericrasch.com on Apr 16, 2009
@Erik White: Thank you for providing your twist on this great tutorial. From what I was able to test, Marc's map works in almost all the browsers, whereas Erik's does not work in IE 6/7. I'm trying to work out the bugs, but it pretty much comes down to the Javascript code. I'll post any solution I find.
#18. yeah on Apr 16, 2009
I'm totally new to jquery and using google maps. So this question might seem stupid to some. Instead of adding random markers I want to add specific locations (and have the list on the side correspond to markers). What part of the code do I need to take out or change in order to achieve this?
#19. alan http://www.design4life.org on Apr 16, 2009
I was looking in your skills section,Give your self another star for design.You are a 5 star designer.
Good job on everything,I like everything you are doing.
#20. Kelvin on Apr 19, 2009
Excellent tutorial with detail description and supplementary code.

Thanks for sharing.
#21. Bill Fisher on Apr 25, 2009

Great tutorial! Thanks especially for introducing me to an easy way to recreate the infoWindow.


I am having trouble, however, with loading content from PHP/MySQL into the infoWindow and then acting upon that content with jQuery... I can get the content there, but can't get the jQuery working. I think it comes down to the event handling, but I am really not sure. A lot of people on the Google Maps list seem to be having similar trouble...


My point is: I think a lot of folks could use a tutorial on this issue (myself included) and you are obviously a good teacher, so how about it?


Thanks again for the great tutorial!

#22. David on May 04, 2009
Is there a way you can highlight the sidebar item with the corresponding info/item bubble that shows up in the google map?
#23. biuuu http://www.biuuu.com/ on May 04, 2009
very excellent! thank you!
#24. adhitia on May 17, 2009
hi..i interest to your script, and i find some problem, maybe you can help..
i can combine between your gmapJquery with Drag&drop Jquery
here is the script

//asumption this is the MAP Script----

//and this is drag&drop script
$(function() {
// there's the gallery and the cart
var $gallery = $('.kiri')//, $cart = $('#cart');
// let the gallery items be draggable
$('#compare').draggable({
cancel: 'a.ui-icon',// clicking an icon won't initiate dragging
revert: 'invalid', // when not dropped, the item will revert back to its initial position
containment: $('#demo-frame').length ? '#demo-frame' : 'document', // stick to demo-frame if present
helper: 'clone',
cursor: 'move'
});

if i see in firebug, it say " $("#compare").draggable is not a function "
can anyone help me??
#25. Wes http://wesbaker.com on May 29, 2009
Thanks for the great tutorial, it got me out of a tight spot.

I do have one question though. with the moveend event listener, what happens if you were to have one point and its set as the center. The map doesn't move then and therefore the listener is never triggered, any thoughts on how to get around that?
#26. Rob C http://www.directorymix.com/ on May 31, 2009
I just want to thank you for a great resource. I am relatively new to gMaps, and am basically blundering around the web reading up on it. I just so happen to luckily click on your url and very glad that I did.

Once question though, although google allows you to load up jQuery form their server, I can still use my own on my server correct? Obviously I'll try myself, but figured I'd ask as well.

Thanks for the great resource!

Rob
#27. Babji on Jun 01, 2009
If I want to have text field(s) where user enters the address (street, city , zip ) and then based on this info how do I invoke the API to render the MAP.
The code shows the usage of latitude and longitude?
Thanks
#28. Mark on Jun 04, 2009
Same problem as Babji..
I want to be able to just provide an address.. unless there is a way to automatically (via php?) get the latitude and longitude values of a given addres..

Thanks a lot,

Mark.
#29. Vitaly Vedernikov on Jun 05, 2009
Thanks, Mark. Lool at this.
#30. Erik White http://erikwhite.net on Jun 06, 2009
I made a small tweak to my code so it now works in IE7 (I can't test IE6 at the moment, but hopefully it'll work as well)

You can try it at http://erikwhite.net/gmapjquery.html

My code builds on Marc's code by adding:
-Cycling of markers on load
-Linking marker click activity to list highlighting
-Improved toggling behaviour for markers and list items
-Loading marker locations from an array which also stores marker labels and extra information
-Dynamically calculating the cycle time between markers, depending on the total number of markers

You can see another example here (this site isn't quite finished yet):

http://southamptonspitfires.co.uk/media/venues
#31. Kim http://www.restaurangbloggen.se on Jun 11, 2009
Hi

First: This is by far the best jquery / Gmap tutorial ever :D

But i have a problem, i am building a restaurantsite where you can choose areas in Stockholm and all restaurants within a chosen category and area will be displayed on the map.

The problem is the $("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
The message-DIV it does not appear when i do a second search on the page, only the first time.

Im not even sure where to start debugging :( is this some kind of memory leakage ?

I would really appreciate if you have some advice to this problem

Here is a link to the beta page of the map:
http://testwebb.restaurangbloggen.se/Restaurangkartan.aspx

just choose anything from the drop down menus, first round will display the #message on the map
but the second time you do a search with the drop down menu the #message does not appear anymore

//Kim
#32. Marc Grabanski http://marcgrabanski.com on Jun 11, 2009
Kim: the message div's CSS is display none.. $("#message").show() takes care of your problem.
#33. Kim http://www.restaurangbloggen.se on Jun 12, 2009
Whooops couldn't see the forest because of all the trees :P as we say in sweden

cheers mate =)
#34. Kim http://www.restaurangbloggen.se on Jun 12, 2009
Hi Marc

just got home from work checked everywhere on page, im not sure it is because it is display none

Since

$("#message").fadeIn().css({ top: markerOffset.y, left: markerOffset.x });

should show the #message div, the weird thing is that it does work the first round but not the second round when i do a new search.

Might there be some kind of DOM object i have to clear/empty?
#35. William http://www.vmoptions.com/Internet/ on Jun 14, 2009
Nice tutorial. Now all I need to do is figure out how to embed it into my CMS!
#36. taliesin on Jun 25, 2009
I am no coder and I got the script working - which has to say something about the quality of the walk through - Thanks good job! I There is a question in an earlier post about just listing markers but no response and I have seen Erik's work with loading from an array. What code is needed to replace the random markers with an array like Erik's. Any pointers would be great the examples on the Google Maps site are for random markers so don't help.
#37. Marc Grabanski http://marcgrabanski.com on Jun 25, 2009
#38. taliesin on Jun 25, 2009
Hi Marc, yes I had already read that but seemed like "over egging the pudding" all I wanted was to show a list of fixed markers instead of the random ones - thanks all the same.
#39. M http://www.sandboxm.com on Jun 26, 2009
Great article, Marc. Kudos!

I have built on your tutorial and tweaked it to display marker points between 2 points. I use KML data from Google Maps and then parse it to display the markers.
http://www.sandboxm.com/jquery-and-google-maps/

The final demo is here: http://www.sandboxm.com/examples/DirectionsGmapJQuery.html

Thanks once again!
M
#40. Porto de Galinhas http://www.portodegalinhas.wiki.br on Jun 29, 2009
Thanks for the explanation, I was looking for a Jquery solution to this on my maps. I found some good tutorials on how to do it on Javascript but this is just better. Thanks again.
#41. Weblover on Jun 30, 2009
Thank you very much for your useful jQuery Google Map tutorial and clear explanation.
I arrive your page when I Google with this keyword combinations "showing google maps in jquery".
Your page is at the first. I get the right place. :)
Your tutorial save me (as well as all others).
Thanks again.
#42. Henry on Jun 30, 2009
Is there any way to do this with a saved google map?
#43. Suzy on Jul 01, 2009
Great tutorial! I'd like to try this however before I start I'm wondering if it's possible to use custom marker icons rather than the default red ones? such as in this Google tutorial -
http://code.google.com/apis/maps/articles/customicons.html

If so it would be great!
#44. Tony http://zierniemann.com on Jul 02, 2009
@suzy

Before you create your marker, create an icon. Then in the "new GMarker" add the icon you just created...


var icon = new GIcon();
icon.image = "http://www.mysite.com/images/marker_icon.png";
icon.iconSize = new GSize(45, 48);
icon.iconAnchor = new GPoint(8, 42);
icon.infoWindowAnchor = new GPoint(43, 6);

var marker = new GMarker(point, icon);
^^^^


That's all there is to it. You can also create a separate shadow image as an attribute of the icon.

Hope that helps.
#45. Suzy on Jul 04, 2009
Great! thanks for the reply, I'll try this out!
#46. Paul on Jul 05, 2009
Has anyone managed to get the hover state for the links to work in IE? I've tried adding the csshover.htc file but this doesn't work.

Thanks
Paul

Also Suzy I found this great for generating markers
http://www.powerhut.co.uk/googlemaps/custom_markers.php
#47. Your name http://www.big-bug.net on Jul 06, 2009
Very Many Thanks bro! it is usefully!
#48. Jeff Goldenson http://www.buildingways.com on Jul 20, 2009
Marc and List -
First off thanks. This is great.

I was wondering if anybody has added zoom-in / zoom-out to this push button navigation? I'm going to be working with a large custom map and was curious there's a way include a zoom out from current point, then pan normally at the higher elevation; then zoom in to the new point. A pull-out/push in sort of thing.

Granted this is tile intensive but....suggestions?
#49. TuVinhSoft http://www.tuvinh.com on Jul 22, 2009
This is truly great tutorial. I can easy add Google Map to my website. Thanks for sharing.
#50. Tom H on Jul 30, 2009
Thanks so much for this excellent and detailed tutorial!
#51. Pasi Hietanen http://domain.com on Aug 07, 2009
You really know how to write a tutorial. Thank you. This is is very useful.
#52. Atea Webdevelopment http://www.atea-webdevlopment.nl on Aug 26, 2009
Thanks, very usefull and simple example, and these boxes are way more flexible than the google maps infoboxes. I got it to work on mouseover/out.
#53. Tom http://www.18aproductions.co.uk on Aug 28, 2009
Hi,
Brilliant tutorial thanks, really well written and easy to follow! Now I'm going to go and get an API key to have a play!

Thanks,

Tom
#54. Cyber Valdez http://www.cybervaldez.com on Sep 04, 2009
Awesome! this helps me a lot!
#55. chandler http://domain.com on Sep 05, 2009
Hi,
Brilliant tutorial , really well written and easy to follow! Now I'm going to go and get an API key to have a play!

Thanks Marc Grabanski,

chandler
#56. bUrAK http://www.reklam-fabrikasi.com on Sep 06, 2009
Great tutorial. clean and simple yet very effective. Much thanx
#57. Dee on Sep 11, 2009
Good tutorial. Can this work in Adobe air (html /ajax)?
#58. Roy Prawira http://roy.prawira.com on Sep 15, 2009
Such a good tutorial Marc, thanks for your effort ...

I need something to ask about the pane options. You are using G_MAP_FLOAT_SHADOW_PANE as a default pane in your tutorial. In my case, I should create form inside info window (which is using your method, in this tutorial), since I need the info window appear on top of all layer (to make the click/focus events work on my form) so I change pane option to G_MAP_FLOAT_PANE because that's the highest layer AFAIK.

When we click the map, the map should create a new marker (done and no problem) and the info window that contains the form is open. But when I try to click a button or fill the form, the info window didn't react anything to my event and the map added a new marker instead of react to the form event.

Do you have any suggestion about this, and sorry could not give you a code because the code running on my local and a little bit bulk to copy paste in here :)

Thanks in advance Marc
#59. запознанства http://vipdating.bg/запознанства/ on Sep 18, 2009
That is good code..thanks and cheers!:)
#60. Briana T http://www.virtual-essentials.com on Sep 24, 2009
I don't leave alot of comments as I navigate around the web, but everyone once in a while you run into a tutorial that makes you stop and say, "Great Job!" and "Thank You!". This is one of those for sure. Very nice work. Much appreciated, Mark ;-)
#61. Brian http://www.bidsoftperu.com on Sep 30, 2009
<h1>Very good Toturial to begin, thanks!!!</h1>
#62. JJJ2 http://domain.com on Oct 14, 2009
Hi guys..is it possible to modify the current script so that I can mouseover thumbnails & have the GoogleMap Marker automatically reposition ?

Thanks.
#63. baddot http://www.baddot.com on Oct 20, 2009
hi can i know how do i add address ?
#64. Mohamed http://elle.free-h.net on Oct 20, 2009
I Just want to say thank you.
#65. nicolas http://www.stiuvou.ch on Oct 22, 2009
I can really use this tutorial for my new university project, thx a lot.
#66. WordPress http://www.wordpresser.ru on Nov 07, 2009
Great article, very helpfull, Thanks!
#67. الشله http://www.s22s.com/ on Nov 15, 2009
Hello .. Very beautiful and gorgeous ..
That's what I was looking for.
Thank you very much
#68. anon http://domain.com on Nov 15, 2009
very clear explanation of how to use google maps with jquery - thank you - i only wish other technical writers were are clear as you are - thanks again!
#69. Marc Friederich http://www.antistatique.net on Nov 24, 2009
Nice tutorial.
Did you find some improvements with API v3 ? I still need v2 for some project like own map layer integration and switching to euclidian projection. Will be interesting to adapt this article with API v3. yes ? Thank's anyway for sharing.
#70. Jeff Seaman http://campgroundautomation.com on Nov 30, 2009
Thank you very much for the tutorial. Extremely straightforward and helpful.
#71. noelferreira http://www.amena.tcpnsa.com/Amena/Localizacao on Dec 02, 2009
Hi guys.

First of all thanks for the great tutorial.
I managed to put everything working just as i want in all browsers but not in IE 6/7/... versions.
When cliclink in the marks nothing happens. The script stops and i don't know hot to debug using IE.

Please check it here:

http://www.amena.tcpnsa.com/Amena/Localizacao

or here:

http://www.amena.tcpnsa.com/Associados-e-Profissionais

Any help would be appreciated.

Thanks in advance. And again ... congratulations on the great job you have done!

noel
#72. John http://www.dtelepathy.com/blog/telepathy/maps on Dec 03, 2009
Great tutorial on setting up a map using the API... man that thing can be frustrating at time. I really like/appreciate the work you put into this.

Cheers!
#73. Tevez322 http://domain.com on Dec 08, 2009
Can javascript be invoked inside the info window content using this approach?
Coz as we know in the standart GMaps api openInfoWindowHTML, javascript is not allowed.
#74. Marc Grabanski http://marcgrabanski.com on Dec 08, 2009
Yes, JavaScript can be invoked from an infowindow in this method because all we are doing is injecting straight HTML inside the window.
#75. Tevez322 http://domain.com on Dec 09, 2009
Cool! Then this solves the limitation of google's openInfoWindowHTML not allowing javascript inside.
#76. Shawn http://www.mayzes.org on Dec 28, 2009
I have created a jQuery plugin for Google Maps. Check it out here: http://www.mayzes.org/googlemaps.jquery.html. :)
#77. Your name on Jan 17, 2010
Hello Friend !

i want to create map like this

http://aredesforgirls.com.br/ ( Click on the "localizao" Button )

Hope you 'll find it.

Thanks with regards
Yash Mistrey
#78. Elemental - web and mobile solutions http://www.elemental.co.za on Jan 26, 2010
Thanks for the awesome tutorial. Loving Jquery and google maps!

keep the good working flowing!

#79. ziza http://www.ziza.net on Jan 30, 2010
JQuery is great script
#80. Roger on Feb 07, 2010
Thanks Marc, this was very useful!

Kim - and anyone else who is wondering why the message doesn't appear when you click the marker a second time - it's because the function assigned to var moveEnd is attached to the GMaps "moveEnd" event, and this event only fires if the map actually has to pan. The second time you click the marker the map doesn't have to mover anywhere, so the message is not faded in.

You can fix this by removing these lines from the finished code:
var moveEnd = GEvent.addListener(map, "moveend", function(){
...[leave the content here!]...
GEvent.removeListener(moveEnd);
});

The downside is that the message will appear before the map finishes panning to the marker location - but if you move the line
map.panTo(marker.getLatLng());
to the top of the displayPoint function then this is barely noticeable.
#81. Darryl http://domain.com on Feb 10, 2010
great tutorial!

Is there any way of making a clickable link inside #message? I have tried, but when there is a marker under it, it selects this instead of the link

thanks
#82. Steve http://www.giantpeachdesign.com on Feb 12, 2010
I like it a lot. JQUERY really is the nuts.
#83. communicat http://www.whatcom.it 1 month, 3 days ago
This is the way step-by-step tutorials should be written!
Keep posting!
#84. Jeremy Coulson http://www.frederickcountyva.gov 1 month, 2 days ago
Hey, this looks like it's EXACTLY what I need to knock out a project fast at work. I have a small problem, however. I have gotten an API key from Google, but every time I put it in, I'm told I need a new one. So, I go get a new one. Of course, it gives me the same one. What's going on?
#85. Lorenz http://webmappingworld.com 1 month, 1 day ago
Thanx man..really informative!!
#86. James http://cret.ca 1 month, 1 day ago
This comment is for Jeremy Coulson. I just ran into this issue. It is probably because you have your map KEY in QUOTES. Do not put any quotes around the map key!
#87. japboy http://nutramax.com.ph 3 weeks, 3 days ago
Thanks for sharing!
#88. William Yates http://www.ces.census.gov 3 weeks, 1 day ago
cool example


<!--
<div class="map" address="1050 Massachusetts Ave, Cambridge, MA 02138-5359"></div>
<div class="map" address="380 Cross Creek Drive, Huntingtown, MD 20639"></div>

<script language="Javascript" type="text/javascript">
$(document).ready(function(){

function drawMap(result, map) {
if (result.Status.code == G_GEO_SUCCESS) {
var geocode = result.Placemark[0].Point.coordinates;

var center = new GLatLng(geocode[1], geocode[0]);

map.setCenter(center, 9);
map.addOverlay(new GMarker(center));
}
}

var geo = new GClientGeocoder();

$('.map').each(
function(n, elm) {
var map = new GMap2($(elm).get(0));
geo.getLocations($(elm).attr('address'), function(result) {drawMap(result, map)});
}
);

});
</script>
-->
#89. Gabriel http://www.gaboesquivel.com 3 weeks, 1 day ago
Just what I needed !! Thanks.
#90. pabx panasonic http://djayabersama.com 2 weeks, 4 days ago
very nice thank's :)
#91. Steve 3 days, 3 hours ago
Is it possible to add the default Map zoom controls back in? So users dont have to guess that double-click zooms the map.
#92. faiz http://domain.com 2 days, 3 hours ago
hi dear,
this is really a nice tutorial
I am not expert in all these programming.
but I am trying to do some thing, in which I need help
I want to show just 2 location and the pointer show only that locations.
1 location is in Canada and other is USA.
so can you tell me how can I do this....
#93. Reklam http://www.reklamgrafik.com 1 day, 18 hours ago
Thanks for this great article. It was very heplfull for me.

Leave a Comment

Other Reading - Categories