The Objective.
This tutorial will show you how to embed a Google Map in to a website. You will need to create a Google account if you do not have one already. I broke the process down in to five simple steps and included a link to a working example.
The Header.Insert the following tags in the <head> of your document. Then,
edit the Google API key below (key=GoogleAPIkey).
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAoMOJatw3uyEScB50Mr77zxTbBjeJC5OepS89rel7GdJxD1-WLRS2pZIcAM7oxTtSFl3u5DcA6NQK3w" type="text/javascript"></script>
<script language="JavaScript" src="maps.js"></script>
<link href="map.css" rel="stylesheet" type="text/css" />
The Body Tag.
Replace Body Tag with the following code:
<body onload="load()" onunload="GUnload()">
The HTML.
Insert the map <div> where ever you would like your map to be displayed
<div id="map"></div>
The JavaScriptSave the JavaScript below as "maps.js", modify, then go to
Geocoder to get the new GPoint Coordinates. NOTE: You can now click the "Link to this page" hotlink on Google Maps, to find the coordinates. Simply copy and paste from the line of HTML code.
function load() {
if (GBrowserIsCompatible()) {
function createMarker(point,html) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
var map = new GMap(document.getElementById("map"));
var point = new GPoint(-104.924927, 39.861263);
var point2 = new GPoint(-105.208168, 39.786906);
var html = '<br /><b>Dan Olsavsky</b><br />Denver, CO';
html += '<form action="http://maps.google.com/maps" method="get" target="_blank">';
html += '<i>Directions to here from</i>: <br />';
html += '<input type="text" name="saddr" value="" size="25"><br />';
html += '<input type="hidden" name="daddr" value="Denver, CO" />';
html += '<input type="hidden" name="hl" value="en">';
html += '<input type="submit" value="Directions"/></form>';
var htm2 = '<br /><b>Dan Olsavsky</b><br />Golden, CO';
htm2 += '<form action="http://maps.google.com/maps" method="get" target="_blank">';
htm2 += '<i>Directions to here from</i>: <br />';
htm2 += '<input type="text" name="saddr" value="" size="25"><br />';
htm2 += '<input type="hidden" name="daddr" value="Golden, CO" />';
htm2 += '<input type="hidden" name="h2" value="en">';
htm2 += '<input type="submit" value="Directions"/></form>';
//Create Marker
var marker = new createMarker(point, html);
var marker2 = new createMarker(point2, htm2);
//Edit Controls
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(point, 9);
//Add Overlay
map.addOverlay(marker);
map.addOverlay(marker2);
//Add info window
marker.openInfoWindowHtml(html);
marker.openInfoWindowHtml(html2);
}
}
The CSSCreate a style sheet named "map.css" and create a selector for the map id.
/* Google Map CSS */
#map {
width:400px;
height:400px;
}
The Example.
http://danolsavsky.com/map.html
Help. Google Maps WikiAdvancedhttp://www.econym.demon.co.uk/googlemaps/index.htm
0 Comments:
Post a Comment
<< Home