How to add Google Maps to WordPress

In this brief tutorial you will learn how to add Google Maps to you WordPress blog.

1 Copy the code below:

<script type="text/javascript"
src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=GET YOUR GOOGLE API KEY">
</script>
<script type="text/javascript">
    function initialize() {
	var mapCheck = document.getElementById("map_canvas");
	if(mapCheck){
      if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"));
	var address = map_canvas.getAttribute("address");
	var geocoder = new GClientGeocoder;
	map.addMapType(G_PHYSICAL_MAP);
	geocoder.getLatLng(address, function(point){
	if(point){
		map.clearOverlays();
		map.setCenter(point, 15, G_PHYSICAL_MAP);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		map.addControl(new GLargeMapControl());
        	map.addControl(new GMapTypeControl());
	}
  	});
}}
}
</script>

paste the code into the head of wp-content/theme/YOUR THEME/header.php

2 Copy and paste the code below in to any post you want a map on:

<div id="map_canvas" style="width:740px; height:300px;" address="Boulder, CO">

You can change the size of the map and the location.
The adress can go from exact to just the state or country.

You can add atributes in the div tag to do any thing you want just be sure to add the functionality to the java script.
Some great resources for learning more about the Google Maps API are:
http://www.google.com/help/maps/tour
http://www.youtube.com/watch?v=hYB0mn5zh2c&feature=related

We hope you enjoy this script.
Peak Studios
Staff

8 Responses to “How to add Google Maps to WordPress”

  1. Joe Says:

    I like this google map intergration. I can now display my address to users on an easy to read interface.

  2. Keith Says:

    Can you add special stuff to the maps like pop up windows?

  3. Janet Says:

    I’ve heard that Google is coming out with new features on their maps and tried out this code here. It works great and even shows the newer Google Maps features.

  4. Lindsay Says:

    Google Maps are so cool. I’m using this one combined with my own coding and made some unqiue maps appear on my website.

  5. Jared Says:

    Maps always give users the functionality to display their location on the map to their browsers.

  6. Alex Says:

    Does anyone know where I can get my Google API from?

  7. Keith Says:

    The Google API can be obtained at http://code.google.com/apis/maps/signup.html

    Just note that you will need to have an account with Google to get an API key.

  8. Brad Says:

    Thanks for the code. I’ll try this on my site now.

Leave a Reply

You must be logged in to post a comment.