Tutorial: Embedding a funky Google Map into your site, with multiple marked locations the user can jump to.

I had to get this going for a section on our work intranet to mark properties we own and provide information on each property, so I figured i'd share the code to other people interested in playing with the Google Maps API.

It's quite a basic script.. you define an array of locations, with longitude/lattitude coordinates and information about each place, and then include the API scripts to initiate the map and a basic little "moveMap()" function that jumps the view window to the clicked location, and pops up an info window like you see at http://maps.google.com when you look an address up.

Before this will work, you will have to get a Google Maps API key (it's instant and no signup required, it just binds you to working within a URL so they know where the API is being used).. you can get it at: http://code.google.com/apis/maps/signup.html

I've commented the code below where I think it's necessary.. but feel free to comment/contact-me if you need any of it explained better. Also, I'm pretty new to JavaScript as a whole, so there could be better ways to do this.. I just did a LOT of googling for each bit and patched it all together until it worked.


Edit: Posterous's code display is really messed up, i'll figure it out later and edit the post, for now here's a text file of the code: http://www.11ty.net/files/mapscode.txt

 

Loading mentions Retweet

Comments (0)

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     Connect     twitter

About

I am the senior web developer & general all-round web guy at Sydney Ports Corporation, and also help medium business with web solutions via Octosis.com.. I'm obsessed with all things web, and you can find me in most of the usual places ;)

www.callanback.com/twitter
www.callanback.com/facebook
www.callanback.com/linkedin
www.callanback.com/delicious
www.callanback.com/reddit
www.callanback.com/digg
www.callanback.com/google
www.callanback.com/flickr