GitXplorerGitXplorer
m

jQuery-Geolocation

public
67 stars
26 forks
2 issues

Commits

List of commits on branch master.
Unverified
8fdcea3c172d7dd1c6e8ab2dc36c511b94021daa

Merge pull request #6 from primus852/patch-1

mmanuelbieh committed 9 years ago
Unverified
a5ccc4626a85235bdc84a474756686f3275ac7be

Update bower.json

pprimus852 committed 9 years ago
Unverified
6791f96b547fe14c6e6b9a4fc53dcd74dbca8ee3

Update package.json

mmanuelbieh committed 9 years ago
Unverified
9e79b811c47c969b85b140bdec46b5c3dc45e9a2

Update bower.json

mmanuelbieh committed 9 years ago
Unverified
04083777937d1a7be7adb544f83caf17e3d90ddd

Update package.json

mmanuelbieh committed 9 years ago
Unverified
84214342c41e3cc0be2a6d91b34429a0d1fb2910

Merge pull request #4 from holtkamp/patch-1

mmanuelbieh committed 9 years ago

README

The README file for this repository.

jQuery Geolocation

A small jQuery plugin which acts as a simplification of the Geolocation API.

Instead of using navigator.geolocation.getCurrentPosition you can now just use the jQuery methods $.geolocation.get() or $.geolocation.watch().

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);

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 this also works with some non-standard Geolocation APIs like Google Gears or Blackberry Location.

Usage

$.geolocation.clearWatch(integer watchID)

Stops tracking of the user for the according watchID.

$.geolocation.get(object config)

Get the current position of the user

Config properties

  • error
    Function to call if geolocation request failed
  • fail
    Alias for error
  • options Options for the geolocation request
    • enableHighAccuracy
    • maximumAge
    • timeout
  • success
    Function to call if geolocation request was successful
  • win
    Alias for success

$.geolocation.getCurrentPosition(callback success, callback error, object settings)

Get the current position of the user (API standard behavior)

Parameters

success Function to call if geolocation request was successful
error Function to call if geolocation request failed
options Options for the geolocation request

  • enableHighAccuracy
  • maximumAge
  • timeout

$.geolocation.stop(integer watchID)

Stops tracking of the user for the according watchID.

$.geolocation.stopAll()

Stops all running watchPosition callbacks.

$.geolocation.watch(object config)

Track the movement of the user Returns: watchID (Integer)

Config properties

  • error
    Function to call if geolocation request failed
  • fail
    Alias for error
  • settings Options for the geolocation request
    • enableHighAccuracy
    • maximumAge
    • timeout
  • success
    Function to call if geolocation request was successful
  • win
    Alias for success

$.geolocation.watchPosition(callback success, callback error, object settings)

Track the movement of the user (API standard behavior) Returns: watchID (Integer)

Parameters

success Function to call if geolocation request was successful
error Function to call if geolocation request failed
options Options for the geolocation request

  • enableHighAccuracy
  • maximumAge
  • timeout

Examples

function alertMyPosition(position) {
	alert("Your position is " + position.coords.latitude + ", " + position.coords.longitude);
}

function noLocation(error) {
	alert("No location info available. Error code: " + error.code);
}

$('#getPositionButton').on('click', function() {
	$.geolocation.get({win: alertMyPosition, fail: noLocation});
});

$('#watchPositionButton').on('click', function() {
	// alertMyPosition is called each time the user's position changes
	myPosition = $.geolocation.watch({win: alertMyPosition}); 
});

$('#stopButton').on('click', function() {
	$.geolocation.stop(myPosition);
});

Deferreds

New in 1.1.0: jQuery Deferreds are now supported for get and getCurrentPosition. Just use: $.geolocation.get().done(successCallback).fail(errorCallback);

Attention: Deferreds support is in beta state.

Demo

You can find a demo here