1 // A shim to implement the W3C Geolocation API Specification using Gears
2 if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) (function(){
6 // We are already defined. Hooray!
7 if (window.google && google.gears) {
14 if (typeof GearsFactory != 'undefined') {
15 factory = new GearsFactory();
19 factory = new ActiveXObject('Gears.Factory');
20 // privateSetGlobalObject is only required and supported on WinCE.
21 if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
22 factory.privateSetGlobalObject(this);
26 if ((typeof navigator.mimeTypes != 'undefined')
27 && navigator.mimeTypes["application/x-googlegears"]) {
28 factory = document.createElement("object");
29 factory.style.display = "none";
32 factory.type = "application/x-googlegears";
33 document.documentElement.appendChild(factory);
38 // *Do not* define any objects if Gears is not installed. This mimics the
39 // behavior of Gears defining the objects in the future.
44 // Now set up the objects, being careful not to overwrite anything.
46 // Note: In Internet Explorer for Windows Mobile, you can't add properties to
47 // the window object. However, global objects are automatically added as
48 // properties of the window object in all browsers.
54 google.gears = {factory: factory};
59 var GearsGeoLocation = (function() {
61 var geo = google.gears.factory.create('beta.geolocation');
63 var wrapSuccess = function(callback, self) { // wrap it for lastPosition love
64 return function(position) {
66 self.lastPosition = position;
78 getCurrentPosition: function(successCallback, errorCallback, options) {
80 var sc = wrapSuccess(successCallback, self);
81 geo.getCurrentPosition(sc, errorCallback, options);
84 watchPosition: function(successCallback, errorCallback, options) {
85 geo.watchPosition(successCallback, errorCallback, options);
88 clearWatch: function(watchId) {
89 geo.clearWatch(watchId);
92 getPermission: function(siteName, imageUrl, extraMessage) {
93 geo.getPermission(siteName, imageUrl, extraMessage);
99 // If you have Gears installed use that
100 if (window.google && google.gears) {
101 navigator.geolocation = GearsGeoLocation();