Guest User

geometa

a guest
Jun 20th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2007, Google Inc.
  2. //
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are met:
  5. //
  6. //  1. Redistributions of source code must retain the above copyright notice,
  7. //     this list of conditions and the following disclaimer.
  8. //  2. Redistributions in binary form must reproduce the above copyright notice,
  9. //     this list of conditions and the following disclaimer in the documentation
  10. //     and/or other materials provided with the distribution.
  11. //  3. Neither the name of Google Inc. nor the names of its contributors may be
  12. //     used to endorse or promote products derived from this software without
  13. //     specific prior written permission.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  18. // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. //
  26. // Sets up google.gears.*, which is *the only* supported way to access Gears.
  27. //
  28. // Circumvent this file at your own risk!
  29. //
  30. // In the future, Gears may automatically define google.gears.* without this
  31. // file. Gears may use these objects to transparently fix bugs and compatibility
  32. // issues. Applications that use the code below will continue to work seamlessly
  33. // when that happens.
  34.  
  35. (function () {
  36.     // We are already defined. Hooray!
  37.     if (window.google && google.gears) {
  38.         return;
  39.     }
  40.  
  41.     var factory = null;
  42.  
  43.     // Firefox
  44.     if (typeof GearsFactory != 'undefined') {
  45.         factory = new GearsFactory();
  46.     } else {
  47.         // IE
  48.         try {
  49.             factory = new ActiveXObject('Gears.Factory');
  50.             // privateSetGlobalObject is only required and supported on IE Mobile on
  51.             // WinCE.
  52.             if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
  53.                 factory.privateSetGlobalObject(this);
  54.             }
  55.         } catch (e) {
  56.             // Safari
  57.             if ((typeof navigator.mimeTypes != 'undefined')
  58.            && navigator.mimeTypes["application/x-googlegears"]) {
  59.                 factory = document.createElement("object");
  60.                 factory.style.display = "none";
  61.                 factory.width = 0;
  62.                 factory.height = 0;
  63.                 factory.type = "application/x-googlegears";
  64.                 document.documentElement.appendChild(factory);
  65.                 if (factory && (typeof factory.create == 'undefined')) {
  66.                     // If NP_Initialize() returns an error, factory will still be created.
  67.                     // We need to make sure this case doesn't cause Gears to appear to
  68.                     // have been initialized.
  69.                     factory = null;
  70.                 }
  71.             }
  72.         }
  73.     }
  74.  
  75.     // *Do not* define any objects if Gears is not installed. This mimics the
  76.     // behavior of Gears defining the objects in the future.
  77.     if (!factory) {
  78.         return;
  79.     }
  80.  
  81.     // Now set up the objects, being careful not to overwrite anything.
  82.     //
  83.     // Note: In Internet Explorer for Windows Mobile, you can't add properties to
  84.     // the window object. However, global objects are automatically added as
  85.     // properties of the window object in all browsers.
  86.     if (!window.google) {
  87.         google = {};
  88.     }
  89.  
  90.     if (!google.gears) {
  91.         google.gears = { factory: factory };
  92.     }
  93. })();
  94. /**
  95. * Geolocation API crossbrowser support
  96. *
  97. * This library provides a consistent Geolocation interface for miscellaneous
  98. * web browsers. It only supports Javascript in a web browser and is not
  99. * tested and will probably not work for use in Titanium, PhoneGap, etc.
  100. * http://www.w3.org/TR/geolocation-API/
  101. *
  102. * @author Manuel Bieh
  103. * @url http://www.manuel-bieh.de/
  104. * @version 1.0.10
  105. * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
  106. *
  107. * Date $LastChangedDate$
  108. *
  109. */
  110.  
  111.  
  112. ; (function () {
  113.  
  114.     var geolocation = this;
  115.  
  116.     this.init = function () {
  117.  
  118.         try {
  119.  
  120.             // Check for W3C Geolocation API standard support
  121.             if (typeof (navigator.geolocation) != 'undefined') {
  122.  
  123.                 geolocation.type = 'W3C Geolocation API';
  124.                 geolocation.api = navigator.geolocation;
  125.  
  126.                 // Check for Google Gears support. gears_init.js must be included!
  127.             } else if (typeof (window.google) != 'undefined' && typeof (window.google.gears) != 'undefined') {
  128.  
  129.                 geolocation.type = 'Google Gears';
  130.                 geolocation.api = google.gears.factory.create('beta.geolocation');
  131.  
  132.                 // Checks for native Blackberry support
  133.             } else if (typeof (window.blackberry) != 'undefined' && blackberry.location.GPSSupported) {
  134.  
  135.                 geolocation.type = 'Blackberry OS';
  136.                 geolocation.api = new BlackberryLocation();
  137.  
  138.             } else {
  139.  
  140.                 return false;
  141.  
  142.             }
  143.  
  144.             window.navigator.geolocation = geolocation.api;
  145.             window.navigator.geolocation['type'] = geolocation.type;
  146.  
  147.             return true;
  148.  
  149.         } catch (e) {
  150.  
  151.             if (typeof (console) != "undefined") {
  152.                 console.log(e);
  153.             }
  154.  
  155.         }
  156.  
  157.     }
  158.  
  159.     /**
  160.     * Gets the current position of the user and executes a callback function
  161.     *
  162.     * @param function Callback function which is executed on success
  163.     * @param function Callback function which is executed on error
  164.     * @param function Options
  165.     * @return void
  166.     */
  167.     this.getCurrentPosition = function (successCallback, errorCallback, options) {
  168.  
  169.         if (geolocation.api) {
  170.             geolocation.api.getCurrentPosition(successCallback, errorCallback, options);
  171.         }
  172.  
  173.     }
  174.  
  175.     /**
  176.     * Calls a callback function every time the user's position changes
  177.     *
  178.     * @param function Callback function which is executed on success
  179.     * @param function Callback function which is executed on error
  180.     * @param function Options
  181.     * @return integer ID of the watchPosition callback
  182.     */
  183.     this.watchPosition = function (successCallback, errorCallback, options) {
  184.  
  185.         if (geolocation.api) {
  186.             geolocation.watchID = geolocation.api.watchPosition(successCallback, errorCallback, options);
  187.         }
  188.  
  189.         return geolocation.watchID;
  190.  
  191.     }
  192.  
  193.     /**
  194.     * Clears the watchPosition callback specified as first parameter.
  195.     *
  196.     * @param integer ID of the watchPosition
  197.     * @return void
  198.     */
  199.     this.clearWatch = function (watchID) {
  200.  
  201.         if (watchID == NULL) {
  202.             geolocation.api.clearWatch(geolocation.watchID);
  203.         } else {
  204.             geolocation.api.clearWatch(watchID);
  205.         }
  206.  
  207.     }
  208.  
  209.     this.init();
  210.  
  211. })();
  212.  
  213.  
  214.  
  215.  
  216. /**
  217. * Geolocation API wrapper for Blackberry devices
  218. */
  219. function BlackberryLocation() {
  220.  
  221.     bb = this;
  222.  
  223.     this.getCurrentPosition = function (successCallback, errorCallback, options) {
  224.  
  225.         // set to autonomous mode
  226.         blackberry.location.setAidMode(2);
  227.  
  228.         if (blackberry.location.latitude == 0 && blackberry.location.longitude == 0) {
  229.  
  230.             errorCallback.call();
  231.  
  232.         } else {
  233.  
  234.             //blackberry.location.onLocationUpdate(successCallback);
  235.             blackberry.location.refreshLocation();
  236.  
  237.             ts = (parseFloat(navigator.appVersion) >= 4.6) ? new Date(blackberry.location.timestamp) : 0;
  238.             successCallback.call(this, { timestamp: ts, coords: { latitude: blackberry.location.latitude, longitude: blackberry.location.longitude} });
  239.  
  240.         }
  241.  
  242.     }
  243.  
  244.     /**
  245.     * watchPosition simulation for Blackberry
  246.     */
  247.     this.watchPosition = function (successCallback, errorCallback, options) {
  248.  
  249.         interval = (typeof options.maximumAge != 'undefined') ? options.maximumAge : 5000;
  250.  
  251.         watchID = window.setInterval(bb.getCurrentPosition, interval, successCallback, errorCallback, options);
  252.         return watchID;
  253.  
  254.     }
  255.  
  256.     this.clearWatch = function (watchID) {
  257.         window.clearInterval(watchID);
  258.     }
  259.  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment