My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!--
copyright (c) 2009 Google inc.

You are free to copy and use this sample.
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps API Sample</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
<style type="text/css">
body {
font-family: Verdana, Arial, sans serif;
font-size: 11px;
margin: 2px;
}
table.directions th {
background-color:#EEEEEE;
}

img {
color: #000000;
}
</style>
<script type="text/javascript">

Number.prototype.toRad = function() { // convert degrees to radians
return this * Math.PI / 180;
}

Number.prototype.toDeg = function() { // convert radians to degrees (signed)
return this * 180 / Math.PI;
}

Number.prototype.toBrng = function() { // convert radians to degrees (as bearing: 0...360)
return (this.toDeg()+360) % 360;
}

function GetBearing(GLatLng1,GLatLng2)
{

var lat1=GLatLng1.lat();
var lon1=GLatLng1.lng();
var lat2=GLatLng2.lat();
var lon2=GLatLng2.lng();
lat1 = lat1.toRad();
lat2 = lat2.toRad();
var dLon = (lon2-lon1).toRad();

var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
return Math.atan2(y, x).toBrng();
}
var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);

//setDirections("5995 Pacific Mesa Ct, San Diego, CA 92121", "4550 La Jolla Village Dr, San Diego, CA 92122", "en_US");
}
}

function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale });
}

function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
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);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
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);

else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
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);

// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

else alert("An unknown error occurred.");
}
function handleNoFlash(errorCode) {
if (errorCode == FLASH_UNAVAILABLE) {
alert("Error: Flash doesn't appear to be supported by your browser");
return;
}
}
function onGDirectionsLoad()
{
var i=0;
var j=0;
var n=0;
var numb_of_steps=0;
var CurrentRoute=null;
var CurStep=null;
n=gdir.getNumRoutes();
var CurPolyLine=gdir.getPolyline();
var stepCounter=0;
var myHTML="<table Id=\"tDirections\">";
for(i=0;i<n;i++)
{
CurrentRoute=gdir.getRoute(i);
numb_of_steps=CurrentRoute.getNumSteps();
for(j=0;j<numb_of_steps;j++)
{

var index1=CurrentRoute.getStep(j).getPolylineIndex();
var index2=index1+1;
var latlan1=CurPolyLine.getVertex(index1);
var latlan2=CurPolyLine.getVertex(index2);
var ThisYaw=GetBearing(latlan1,latlan2);

var Loc=CurrentRoute.getStep(j).getLatLng();
var panoramaOptions;
var ThisPOV={"yaw":ThisYaw,"pitch":0,"zoom":0};
panoramaOptions = {latlng:Loc, pov:ThisPOV};
var DisplayString=CurrentRoute.getStep(j).getDescriptionHtml();

stepCounter++;
myHTML+="<tr>";
myHTML+="<td>";
myHTML+="<div class=\"steps\">";
myHTML+="<div class=\"dStepDesc\">";
myHTML+=DisplayString;
myHTML+="</div>";
myHTML+="<div class=\"dLat\">";
myHTML+=Loc.lat();
myHTML+="</div>";
myHTML+="<div class=\"dLag\">";
myHTML+=Loc.lng();
myHTML+="</div>";

myHTML+="<div class=\"dPolyLineIndex\">";
myHTML+=""+CurrentRoute.getStep(j).getPolylineIndex();
myHTML+="</div>";


myHTML+="</div>";
myHTML+="</td>";
stepCounter++;
myHTML+="</tr>";
}
}
myHTML+="</table>";

myHTML+="<div id=\"Points\">";
var CurPolyLine = gdir.getPolyline();
for(var c=0;c<CurPolyLine.getVertexCount();c++)
{
var latlan = CurPolyLine.getVertex(c)
myHTML+="<div>";

myHTML+="<div class=\"pLat\">";
myHTML+=latlan.lat();
myHTML+="</div>";
myHTML+=" , ";
myHTML+="<div class=\"pLng\">";
myHTML+=latlan.lng();
myHTML+="</div>";

myHTML+="</div>";
}
myHTML+="</div>";
var myDirectionDiv=document.getElementById("directionsSlide");
myDirectionDiv.innerHTML=myHTML;
var mytip=document.getElementById("lTip");
mytip.innerHTML="Directions Loaded!!...";

}
</script>
</head>
<body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
<h2>Directions</h2>
<div id="lTip">Tip: Click GetDirections to calculate direction steps</div>
<br/>
<table class="directions">
<tr>
<td valign="top">
<div id="map_canvas" style="width: 310px; height: 400px"></div>
<td>

</tr>
<tr>
<td valign="top">
<div id="directions" style="width: 275px"></div>
<td>
</tr>
</table>
<br />
<div id="directionsSlide" >
this is test content
</div>
</body>
</html>

Change log

r2 by mark.dawn on Jan 14, 2010   Diff
First Time Check-In
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 7403 bytes, 211 lines
Powered by Google Project Hosting