question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UserLocation minDisplacement not limiting calls for onUpdate

See original GitHub issue

Description of the issue/bug UserLocation.minDisplacement does not seem to limit the number of calls on UserLocation.onUpdate.

There is currently no documentation available, but I assume that the purpose of the property minDisplacement is to set the minimum distance (meters?) a user’s location has to change before UserLocation will receive an update.

Setting minDisplacement to high values did not make any difference though. UserLocation.onUpdate was called by rotating my phone without moving anywhere.

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
UserLocation,
} from '@react-native-mapbox-gl/maps';

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597, 40.71427],
    [-74.00697, 40.71527],
  ],
};

class BugReportExample extends React.Component {
  onUpdatePosition(location) {
    console.log('Updated position')
    // minDisplacement on UserLocation doesn't seem to limit the 
    // call for onUpdate. 
    this.setState({ location: location });
  }
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource id="idStreetLayer" shape={aLine}>
          <LineLayer id="idStreetLayer" />
        </ShapeSource>
          <UserLocation
            visible={true}
            renderMode={'normal'}
            minDisplacement={5}
            onUpdate={(location) => this.onUpdatePosition(location)}
            showsUserHeadingIndicator={true} />
      </MapView>
    );
  }
}

This might also be related to issue #770

I might just misunderstand the purpose of minDisplacement. If so then this would be a great feature to have.

Versions:

  • Platform: iOS
  • Device: iPhone11
  • Emulator/ Simulator: no
  • OS: 13.4.1
  • react-native-mapbox-gl Version 8.0.0
  • React Native Version 0.62.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
mzucommented, May 8, 2020

Hi @ferdicus. Just tested the branch and onUpdate gets now called as expected, i.e. when minDisplacement is reached. Thanks for taking care of this!

I just wanted to note that when showsUserHeadingIndicator={true} is set, the indicator arrow is also affected. It only updates along with minDisplacement. I assume it’s not possible with this fix to keep the onUpdate callback independent from the heading indicator updates. I just think that most use cases want to see the heading indicator continuously updating and see the displacement updates only in terms of ‘moving a certain distance on the ground’. Maybe the only solution for this case is to keep the displacement at 0 and limit any state updates inside the onUpdate callback instead.

At least there is now a choice since before the minDisplacement value didn’t have any effect on iOS. Thanks 😃

1reaction
mfazekascommented, Apr 28, 2020

The userLocation expects heading for displaying direction. Maybe we can skip calling delegate when minDisplacement is set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UserLocation minDisplacement not limiting calls for onUpdate
Description of the issue/bug UserLocation.minDisplacement does not seem to limit the number of calls on UserLocation.onUpdate.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found