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
|
// A shim to implement the W3C Geolocation API Specification using Gears
if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) (function(){
// -- BEGIN GEARS_INIT
(function() {
// We are already defined. Hooray!
if (window.google && google.gears) {
return;
}
var factory = null;
// Firefox
if (typeof GearsFactory != 'undefined') {
factory = new GearsFactory();
} else {
// IE
try {
factory = new ActiveXObject('Gears.Factory');
// privateSetGlobalObject is only required and supported on WinCE.
if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
factory.privateSetGlobalObject(this);
}
} catch (e) {
// Safari
if ((typeof navigator.mimeTypes != 'undefined')
&& navigator.mimeTypes["application/x-googlegears"]) {
factory = document.createElement("object");
factory.style.display = "none";
factory.width = 0;
factory.height = 0;
factory.type = "application/x-googlegears";
document.documentElement.appendChild(factory);
}
}
}
// *Do not* define any objects if Gears is not installed. This mimics the
// behavior of Gears defining the objects in the future.
if (!factory) {
return;
}
// Now set up the objects, being careful not to overwrite anything.
//
// Note: In Internet Explorer for Windows Mobile, you can't add properties to
// the window object. However, global objects are automatically added as
// properties of the window object in all browsers.
if (!window.google) {
google = {};
}
if (!google.gears) {
google.gears = {factory: factory};
}
})();
// -- END GEARS_INIT
var GearsGeoLocation = (function() {
// -- PRIVATE
var geo = google.gears.factory.create('beta.geolocation');
var wrapSuccess = function(callback, self) { // wrap it for lastPosition love
return function(position) {
callback(position);
self.lastPosition = position;
}
}
// -- PUBLIC
return {
shim: true,
type: "Gears",
lastPosition: null,
getCurrentPosition: function(successCallback, errorCallback, options) {
var self = this;
var sc = wrapSuccess(successCallback, self);
geo.getCurrentPosition(sc, errorCallback, options);
},
watchPosition: function(successCallback, errorCallback, options) {
geo.watchPosition(successCallback, errorCallback, options);
},
clearWatch: function(watchId) {
geo.clearWatch(watchId);
},
getPermission: function(siteName, imageUrl, extraMessage) {
geo.getPermission(siteName, imageUrl, extraMessage);
}
};
});
// If you have Gears installed use that
if (window.google && google.gears) {
navigator.geolocation = GearsGeoLocation();
}
})();
|