mapbox / mapbox/mapbox-gl-js

minimum accuracy before showing GeolocateControl dot

Open
#9,177 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple: needs discussion :speech_balloon:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

The default `GeolocateControl` shows the viewer's position as reported by `navigator.geolocation.watchPosition` immediately, but this often has a very high margin of error. The dot is often in the wrong location, which can be confusing or even dangerous depending on the application.

## Design Alternatives

An even better design would be to show the dot with the radius of confusion as a circle around it (common design pattern in many driving/aviation applications).

## Design

A simpler edit is to allow the user to provide a "minimum accuracy" in meters, and ignore `watchPosition` calls that do not meet this level of accuracy.

### Mock-Up

Will look the same visually, but the geolocation dot will only show once the minimum gps accuracy is met.

### Concepts

New concept is a minimum GPS accuracy, should be documented at https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/control/geolocate_control.js#L77-L81

### Implementation

`navigator.geolocation.watchPosition` already returns an accuracy value (in meters) as `position.coords.accuracy` (see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates)

The `_onSuccess` function of `GeolocateControl` can easily be updated to ignore position events below a threshold accuracy: https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/control/geolocate_control.js#L184

A minimum accuracy can be provided as an optional configuration at https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/control/geolocate_control.js#L14

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/ui/control/geolocate_control.js, especially the configuration documentation near lines 77-81 and the _onSuccess function near line 184. Check how GeolocateControl options are defined near line 14 and inspect existing control tests before making changes. Done means an optional minimum accuracy is documented and position updates below that threshold do not show the geolocation dot.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.