David Thomas Baker » Web » How to setup simple Google Maps on your website

Here's a quick howto on setting up Google Maps on your website.

Ideal for "Contact Us" pages.

Go to http://code.google.com/apis/maps/signup.html to get an API key for your website. An API key is a really long string of random characters. You will get something that looks like this:
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=YOUR_API_KEY_HERE"
type="text/javascript"></script>

Put this <script> tag on the page you want the map to appear on.

<script type="text/javascript">
//<![CDATA[
function loadmap() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.addControl(new GSmallMapControl());
var address = "1 James Street, Burleigh, QLD, Australia";
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(
"<strong>Address</strong><br>Type It Here:"+
" <br>Southport, QLD 4215<br>Australia.");
}
}
);
}
}
$(window).load(function(){loadmap()});
//]]>
</script>

<div id="map" style="width: 300px; height: 400px">
</div>

 

Posted by David Baker in: Web |
Tags: google |
Perm Link: link
Some ads...

Search My Site

Featured Projects

Collector Comics is THE place to buy, sell, and research comics online. Launching soon.
Launch » Screenshot »
Webitor is a kick-ass easy to use, easy to extend, non-database driven Content Management System. Version 2 with reseller plan coming soon.
Launch » Version 1 »
GC Lounge is my own pet social network and test bed for social related code. Made by locals for locals.
Launch »
GG has indexed over half a million recent Trade Mark applications. This revolutionary tool is extremely valuable for industry experts.
Launch »
GCWiFi is the hub for techies interested in joining a ad-hoc wireless mesh spread across the Gold Coast
Launch »
Web based financial client management system
Launch »
OS Commerce modules and template modification
Launch »
View More Projects »

Daves Friends

BlueTeddy
WebSpark
GC Designer Forum
IPWealth Trademarks
Cheap Websites
Bonsai Shop
Webitor CMS Resellers
Hayley Crook
David Novakovic
Ben Novakovic
Richard Morwood
Gold Coast Linux
Aussie Click
CMS Website Design
Inspire Tuition
Gold Coast Music Network and Gold Coast Gig Guide

Chat with Dave

Powered by...

In the works

Webitor - Easy to use Content Management System with Shop, Newsletter, and Reseller plan