Skip to content

Commit

Permalink
Stop playing around with accuracy
Browse files Browse the repository at this point in the history
It's actually in meters, not percentage
  • Loading branch information
cheeaun committed Nov 26, 2022
1 parent 05858a3 commit a3dd2ec
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions assets/components/GeolocateControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,14 @@ export default class GeolocateControl {
this._watching = navigator.geolocation.watchPosition(
(position) => {
console.log({ position });
const { latitude, longitude, accuracy } = position.coords;
const { latitude, longitude } = position.coords;

if (`${[latitude, longitude]}` === `${this._currentLocation}`) return; // No idea why

// console.log({ latitude, longitude });
this._currentLocation = [longitude, latitude];
this._dot.setLngLat(this._currentLocation);

const dotElement = this._dot.getElement();
// Scale is between 1 and 2, accuracy is between 100 and 0
// if accuracy >= 95, scale = 1, opacity = 1
// if accuracy < 95, scale = 2, opacity = 0.5
const scale = 1 + (100 - accuracy) / 100;
const opacity = 1 - (100 - accuracy) / 100 / 2;
dotElement.style.transform = `scale(${scale})`;
dotElement.style.opacity = opacity;
this._compass.classList.toggle('uncertain', opacity < 0.75);

if (!this._dot._addedToMap) {
this._dot.addTo(this._map);
this._dot._addedToMap = true;
Expand Down

0 comments on commit a3dd2ec

Please sign in to comment.