Skip to content
Small JavaScript library for throttling the callbacks from navigator.geolocation.watchPosition
JavaScript HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.



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.


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, 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.

You can’t perform that action at this time.