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&v=2&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
March 11th, 2008 at 12:11 pm
I like this google map intergration. I can now display my address to users on an easy to read interface.
March 27th, 2008 at 5:49 pm
Can you add special stuff to the maps like pop up windows?
May 15th, 2008 at 4:41 pm
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.
May 28th, 2008 at 3:30 pm
Google Maps are so cool. I’m using this one combined with my own coding and made some unqiue maps appear on my website.
June 18th, 2008 at 10:52 am
Maps always give users the functionality to display their location on the map to their browsers.
July 2nd, 2008 at 3:11 pm
Does anyone know where I can get my Google API from?
August 6th, 2008 at 2:07 pm
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.
August 26th, 2008 at 3:54 pm
Thanks for the code. I’ll try this on my site now.