forked from kishikawakatsumi/MapKit-Route-Directions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.html
116 lines (101 loc) · 4.57 KB
/
api.html
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
<!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>Route Map</title>
<script src="http://maps.google.com/maps?file=api&v=2.x&sensor=false&key=ABQIAAAAHbdppQ3MDhGeECdceHXV_hSdG0_H5fikhlv-IEqZhBC4z1KyBxR12kmbllSrnYs8N7ylVtP59PINPg"></script>
<script type="text/javascript">
var map;
var gdir;
var geocoder;
function initialize() {
if (GBrowserIsCompatible()) {
gdir = new GDirections(null, null);
geocoder = new GClientGeocoder();
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
}
}
function loadDirections(from, to, options) {
gdir.load("from: " + from + " to: " + to, options);
}
function loadFromWaypoints(waypoints, options) {
gdir.loadFromWaypoints(waypoints, options);
}
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 onGDirectionsLoad() {
var numRoutes = gdir.getNumRoutes();
var routes = new Array(numRoutes);
for (var i = 0; i < numRoutes; i++) {
routes[i] = gdir.getRoute(i);
}
var numGeocodes = gdir.getNumGeocodes();
var geocodes = new Array(numGeocodes);
for (var i = 0; i < numGeocodes; i++) {
geocodes[i] = gdir.getGeocode(i);
}
alert({ "routes": routes,
"geocodes": geocodes,
"distance": gdir.getDistance(),
"duration": gdir.getDuration(),
"polyline": gdir.getPolyline(),
"status": gdir.getStatus() }.toSource());
}
(function () {
/* atomic objects */
if (!Boolean.prototype.toSource) Boolean.prototype.toSource = function () {
return this.toString();
};
if (!Number.prototype.toSource) Number.prototype.toSource = function () {
return this.toString();
};
if (!String.prototype.toSource) String.prototype.toSource = function () {
return '\"' + this.toString().replace(/[\\\"\']/g, function (m0) {
return '\\' + m0;
}) + '\"';
};
if (!Date.prototype.toSource) Date.prototype.toSource = function () {
return '(new Date(' + this.valueOf() + '))';
};
if (!RegExp.prototype.toSource) RegExp.prototype.toSource = function () {
return this.toString();
};
/* and built-ins */
if (!Function.prototype.toSource) Function.prototype.toSource = function () {
return this.toString();
}
if (!Array.prototype.toSource) Array.prototype.toSource = function () {
var src = [];
for (var i = 0, l = this.length; i < l; i++) {
src[i] = this[i].toSource();
}
return '[' + src.toString() + ']';
};
if (!Object.prototype.toSource) Object.prototype.toSource = function () {
var src = []; // a-ha!
for (var p in this) {
if (!this.hasOwnProperty(p)) continue;
src[src.length] = p.toSource() + ':' + (this[p] ? this[p].toSource() : this[p] === undefined ? 'undefined' : 'null');
} // parens needed to make eval() happy
return '{' + src.toString() + '}';
};
})();
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
</body>
</html>