Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heyman/geolocation-throttle
Small JavaScript library for throttling the callbacks from navigator.geolocation.watchPosition
https://github.com/heyman/geolocation-throttle
Last synced: 1 day ago
JSON representation
Small JavaScript library for throttling the callbacks from navigator.geolocation.watchPosition
- Host: GitHub
- URL: https://github.com/heyman/geolocation-throttle
- Owner: heyman
- Created: 2013-04-01T22:43:17.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-02-20T11:58:39.000Z (over 3 years ago)
- Last Synced: 2023-04-13T15:37:13.831Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 15
- Watchers: 6
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
GeolocationThrottle
===================GeolocationThrottle is a small JavaScript lib for the single purpose of throttling the
number of callbacks that one gets from the HTML5's
`navigator.geolocation.watchPosition `_
function.Why?
----I've found myself in the need for this feature in two different projects, and therefore I thought
someone else might benefit from the code, and I decided to make a re-usable script of it.In both projects where I've needed watchPosition throttling, I've been doing HTTP requests to some backend
system, in the watchPosition's callback, and I've wanted to limit the number of backend requests for
performance and/or API limit reasons.One of the projects where it's used is `What is my zip `_ which is
a small website for retrieving the ZIP code of your current location. Another for which I use
GeolocationThrottle is `Longitude.me `_, a service for sharing your current
location. The third project where I use this lib is `Hotels Near Me `_,
which is a site for finding hotels near your current location.How to use it?
--------------The API is exactly the same as the navigator.geolocation.watchPosition, except that I've added
an extra option *throttleTime* to the options object.Here's an example of how to watch the geo position, but throttle the position callback to at
most once every 5 seconds::GeolocationThrottle.watchPosition(function(position) {
console.log("position:", position);
}, function() {
console.log("Error! Could not get position");
}, {throttleTime: 5000});See example
-----------`Here `_ is a super simple and ugly example page.
You should probably test it with a smartphone that has GPS.Copyright & License
-------------------This plugin is written by `Jonatan Heyman `_ and is licenced as
`Beerware `_.