0

Im using Leaflet.Control.GPS (https://github.com/stefanocudini/leaflet-gps) to locate the users location.

How to add a progress indicator, or a spinner (or some other UX hint) which should appear only when "map.locate" is trying to find the current position of the user?

I already added via Leaflet.Loading (https://github.com/ebrelsford/Leaflet.loading) a spinner to my map, but only works when loading tiles.

Maybe it is possible to combine them?

1

You can not add a progress indicator. There is no way to predict how much time a geolocation query will take.

In order to add a spinner, or any other "waiting message" or UX hint, just display it when starting the geolocation query, and hide it when the query is finished, e.g.:

spinner.show();
map.once('locationfound locationerror', function(ev){
    spinner.hide();
});
map.locate(locateOptions);

The specific way of showing and hiding that UX element is up to you, depending on what you want (a button, a transparent overlay, a "toast" notification, etc etc etc), but the map-related logic should look like that.

  • this geolocate plugin makes it possible: github.com/domoritz/leaflet-locatecontrol. but it is not as accurate and smooth as Leaflet.Control.GPS (github.com/stefanocudini/leaflet-gps). – howard.D Nov 23 '16 at 13:48
  • But that adds a spinner, no a progress indicator. The wording of your questions suggest that you want to be aware of progress. – IvanSanchez Nov 23 '16 at 13:52
  • a spinner would be fine too – howard.D Nov 23 '16 at 13:53
  • Please note that I've edited your question and my answer to reflect that. – IvanSanchez Nov 23 '16 at 13:59
  • any sample or hint how to integrate a font-awesome spinner like in github.com/domoritz/leaflet-locatecontrol. to github.com/stefanocudini/leaflet-gps.? – howard.D Nov 23 '16 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.