├── License.txt
├── README.md
├── bower.json
├── earth.png
├── index.html
├── jquery.geolocation.js
├── jquery.geolocation.min.js
└── package.json
/License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Manuel Bieh
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jQuery Geolocation
2 |
3 | A small jQuery plugin which acts as a simplification of the [Geolocation API](http://dev.w3.org/geo/api/spec-source.html).
4 |
5 | Instead of using navigator.geolocation.getCurrentPosition you can now just use the jQuery methods `$.geolocation.get()` or `$.geolocation.watch()`.
6 |
7 | Contrary to the standard API the only parameter the functions expect is an object with three properties in no particular order: `success`, `error`, `options`. For `success` and `error` you can also use their alias properties `win` (or `done`) and `fail`: `$.geolocation.get({win: function() {}, fail: function() {}, options);`
8 |
9 | You can also use `$.geolocation.getCurrentPosition(success, error, options)` to get native API feeling if this makes you happier. In conjunction with my [Geolocation API polyfill](https://github.com/manuelbieh/Geolocation-API-Polyfill) this also works with some non-standard Geolocation APIs like Google Gears or Blackberry Location.
10 |
11 | ## Usage
12 |
13 | ### $.geolocation.clearWatch(integer watchID)
14 | Stops tracking of the user for the according watchID.
15 |
16 | ### $.geolocation.get(object config)
17 | Get the current position of the user
18 |
19 | #### Config properties
20 |
21 |
22 |
23 | error
24 | Function to call if geolocation request failed
25 |
38 | success
39 | Function to call if geolocation request was successful
40 |
41 |
42 | win
43 | Alias for success
44 |
45 |
46 |
47 |
48 | ### $.geolocation.getCurrentPosition(callback success, callback error, object settings)
49 | Get the current position of the user (API standard behavior)
50 |
51 | #### Parameters
52 |
53 | success Function to call if geolocation request was successful
54 | error Function to call if geolocation request failed
55 | options Options for the geolocation request
56 |
57 |
58 |
enableHighAccuracy
59 |
maximumAge
60 |
timeout
61 |
62 |
63 | ### $.geolocation.stop(integer watchID)
64 |
65 | Stops tracking of the user for the according watchID.
66 |
67 | ### $.geolocation.stopAll()
68 |
69 | Stops all running watchPosition callbacks.
70 |
71 | ### $.geolocation.watch(object config)
72 |
73 | Track the movement of the user
74 | Returns: watchID (Integer)
75 |
76 | #### Config properties
77 |
78 |
79 |
80 | error
81 | Function to call if geolocation request failed
82 |
95 | success
96 | Function to call if geolocation request was successful
97 |
98 |
99 | win
100 | Alias for success
101 |
102 |
103 |
104 |
105 | ### $.geolocation.watchPosition(callback success, callback error, object settings)
106 |
107 | Track the movement of the user (API standard behavior)
108 | Returns: watchID (Integer)
109 |
110 | #### Parameters
111 |
112 | success Function to call if geolocation request was successful
113 | error Function to call if geolocation request failed
114 | options Options for the geolocation request
115 |
116 |
enableHighAccuracy
117 |
maximumAge
118 |
timeout
119 |
120 |
121 |
122 | ## Examples
123 |
function alertMyPosition(position) {
124 | alert("Your position is " + position.coords.latitude + ", " + position.coords.longitude);
125 | }
126 |
127 | function noLocation(error) {
128 | alert("No location info available. Error code: " + error.code);
129 | }
130 |
131 | $('#getPositionButton').on('click', function() {
132 | $.geolocation.get({win: alertMyPosition, fail: noLocation});
133 | });
134 |
135 | $('#watchPositionButton').on('click', function() {
136 | // alertMyPosition is called each time the user's position changes
137 | myPosition = $.geolocation.watch({win: alertMyPosition});
138 | });
139 |
140 | $('#stopButton').on('click', function() {
141 | $.geolocation.stop(myPosition);
142 | });
143 |
144 | ## Deferreds
145 |
146 | New in 1.1.0:
147 | jQuery Deferreds are now supported for `get` and `getCurrentPosition`. Just use:
148 | `$.geolocation.get().done(successCallback).fail(errorCallback);`
149 |
150 | Attention: Deferreds support is in beta state.
151 |
152 | ## Demo
153 | [You can find a demo here](http://manuel-bieh.de/publikationen/scripts/jquery/geolocation/)
154 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-geolocation",
3 | "version": "1.1.1",
4 | "description": "jQuery plugin which acts as a simplification of the Geolocation API.",
5 | "license": "MIT",
6 | "ignore": [
7 | "earth.png",
8 | "index.html"
9 | ],
10 | "dependencies": {
11 | "jquery": ">=1.6.0"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/earth.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/manuelbieh/jQuery-Geolocation/8fdcea3c172d7dd1c6e8ab2dc36c511b94021daa/earth.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
57 |
58 |
121 |
122 |
123 |
124 |
125 |