001.
<!--
002.
copyright (c) 2009 Google inc.
003.
004.
You are free to
copy
and
use
this sample.
005.
License can be found here: http:
006.
-->
007.
010.
<head>
011.
<meta http-equiv=
"content-type"
content=
"text/html; charset=utf-8"
/>
012.
<title>Google Maps API Sample</title>
013.
<script src=
"http://maps.google.com/maps?file=api&;amp;v=2&sensor=false&key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"
></script>
014.
<style type=
"text/css"
>
015.
body {
016.
font-family: Verdana, Arial, sans serif;
017.
font-size: 11px;
018.
margin: 2px;
019.
}
020.
table.directions th {
021.
background-color:#EEEEEE;
022.
}
023.
024.
img {
025.
color: #000000;
026.
}
027.
</style>
028.
<script type=
"text/javascript"
>
029.
030.
var
map;
031.
var
gdir;
032.
var
geocoder = null;
033.
var
addressMarker;
034.
035.
function
initialize() {
036.
if
(GBrowserIsCompatible()) {
037.
map =
new
GMap2(document.getElementById(
"map_canvas"
));
038.
gdir =
new
GDirections(map, document.getElementById(
"directions"
));
039.
GEvent.addListener(gdir,
"load"
, onGDirectionsLoad);
040.
GEvent.addListener(gdir,
"error"
, handleErrors);
041.
042.
setDirections(
"San Francisco"
,
"Mountain View"
,
"en_US"
);
043.
}
044.
}
045.
046.
function
setDirections(fromAddress, toAddress, locale) {
047.
gdir.load(
"from: "
+ fromAddress +
" to: "
+ toAddress,
048.
{
"locale"
: locale });
049.
}
050.
051.
function
handleErrors(){
052.
if
(gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
053.
alert(
"No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: "
+ gdir.getStatus().code);
054.
else
if
(gdir.getStatus().code == G_GEO_SERVER_ERROR)
055.
alert(
"A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: "
+ gdir.getStatus().code);
056.
057.
else
if
(gdir.getStatus().code == G_GEO_MISSING_QUERY)
058.
alert(
"The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: "
+ gdir.getStatus().code);
059.
060.
061.
062.
063.
else
if
(gdir.getStatus().code == G_GEO_BAD_KEY)
064.
alert(
"The given key is either invalid or does not match the domain for which it was given. \n Error code: "
+ gdir.getStatus().code);
065.
066.
else
if
(gdir.getStatus().code == G_GEO_BAD_REQUEST)
067.
alert(
"A directions request could not be successfully parsed.\n Error code: "
+ gdir.getStatus().code);
068.
069.
else
alert(
"An unknown error occurred."
);
070.
}
071.
072.
function
onGDirectionsLoad(){
073.
074.
075.
076.
077.
078.
079.
}
080.
081.
</script>
082.
</head>
083.
<body onload=
"initialize()"
onunload=
"GUnload()"
style=
"font-family: Arial;border: 0 none;"
>
084.
<h2>Maps API Directions Illustrated</h2>
085.
<form action=
"#"
onsubmit=
"setDirections(this.from.value, this.to.value, this.locale.value); return false"
>
086.
<table>
087.
<tr>
088.
<th align=
"right"
>From: </th>
089.
<td>
090.
<input type=
"text"
size=
"25"
id=
"fromAddress"
name=
"from"
value=
"San Francisco"
/>
091.
<td>
092.
<th align=
"right"
> To: </th>
093.
<td align=
"right"
><input type=
"text"
size=
"25"
id=
"toAddress"
name=
"to"
value=
"Mountain View"
/>
094.
<td>
095.
</tr>
096.
<tr>
097.
<th>Language: </th>
098.
<td colspan=
"3"
>
099.
<select id=
"locale"
name=
"locale"
>
100.
<option value=
"en"
selected>English</option>
101.
<option value=
"fr"
>French</option>
102.
<option value=
"de"
>German</option>
103.
<option value=
"ja"
>Japanese</option>
104.
<option value=
"es"
>Spanish</option>
105.
</select>
106.
<input name=
"submit"
type=
"submit"
value=
"Get Directions!"
/>
107.
<td>
108.
</tr>
109.
</table>
110.
</form>
111.
<br/>
112.
<table
class
=
"directions"
>
113.
<tr>
114.
<th>Formatted Directions</th><th>Map</th>
115.
</tr>
116.
<tr>
117.
<td valign=
"top"
>
118.
<div id=
"directions"
style=
"width: 275px"
></div>
119.
<td>
120.
<td valign=
"top"
>
121.
<div id=
"map_canvas"
style=
"width: 310px; height: 400px"
></div>
122.
<td>
123.
</tr>
124.
</table>
125.
</body>
126.
</html>