source: extensions/iPiwigo/www/extensions/jqt.location.js @ 9188

Last change on this file since 9188 was 9188, checked in by Polly, 13 years ago

Adding the Phonegap www folder needed to compile.

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1/*
2
3            _/    _/_/    _/_/_/_/_/                              _/       
4               _/    _/      _/      _/_/    _/    _/    _/_/_/  _/_/_/   
5          _/  _/  _/_/      _/    _/    _/  _/    _/  _/        _/    _/   
6         _/  _/    _/      _/    _/    _/  _/    _/  _/        _/    _/   
7        _/    _/_/  _/    _/      _/_/      _/_/_/    _/_/_/  _/    _/     
8       _/                                                                 
9    _/
10
11    Created by David Kaneda <http://www.davidkaneda.com>
12    Documentation and issue tracking on Google Code <http://code.google.com/p/jqtouch/>
13   
14    Special thanks to Jonathan Stark <http://jonathanstark.com/>
15    and pinch/zoom <http://www.pinchzoom.com/>
16   
17    (c) 2009 by jQTouch project members.
18    See LICENSE.txt for license.
19
20*/
21
22(function($) {
23    if ($.jQTouch)
24    {
25        $.jQTouch.addExtension(function Location(){
26           
27            var latitude, longitude, callback;
28           
29            function checkGeoLocation() {
30                return navigator.geolocation;
31            }
32            function updateLocation(fn) {
33                if (checkGeoLocation())
34                {
35                    callback = fn;
36                    navigator.geolocation.getCurrentPosition(savePosition);
37                    return true;
38                } else {
39                    console.log('Device not capable of geo-location.');
40                    fn(false);
41                    return false;
42                }               
43            }
44            function savePosition(position) {
45                latitude = position.coords.latitude;
46                longitude = position.coords.longitude;
47                if (callback) {
48                    callback(getLocation());
49                }
50            }
51            function getLocation() {
52                if (latitude && longitude) {
53                    return {
54                        latitude: latitude,
55                        longitude: longitude
56                    }
57                } else {
58                    console.log('No location available. Try calling updateLocation() first.');
59                    return false;
60                }
61            }
62            return {
63                updateLocation: updateLocation,
64                getLocation: getLocation
65            }
66        });
67    }
68})(jQuery);
Note: See TracBrowser for help on using the repository browser.