React-native-maps: question about update frequency

Created on 21 Dec 2016  路  3Comments  路  Source: react-native-maps/react-native-maps

Apologies if this isn't the right place to be asking this question.

I've noticed that when I activate the _showsUserLocation_ feature, the blue dot that shows my location seems to receive frequent updates, far more than my RN code does when I call geolocation.watchPosition without any parameters:

this._geolocation.watchPosition(
  (gps) => {
    // ...
  },
  (err) => {
    console.log("Failed to get gpsPosition", err);
  }
);

Is there a way to get the same updates in my RN app that react-native-maps seems to receive?

All 3 comments

I used a timer to force updates at a 3 second rate.

I am not recommending what I did, it may be a very bad idea, but it achieved my goal of faster updates.

const MyMapView = React.createClass({
  mixins: [TimerMixin],
  watchID: null,

  getCurrentPosition() {
    navigator.geolocation.getCurrentPosition(this.geoSuccess, this.geoError, this.options);
  },
  geoWatchStart() {
    if (this.watchID != null) {
      return;
    }
    this.getCurrentPosition();
    this.watchID = navigator.geolocation.watchPosition(this.geoSuccess, this.geoError, this.options);
  },
  geoWatchStop() {
    if (this.watchID == null) {
      return;
    }
    console.log('WaypointScreen:geoWatchStop');
    navigator.geolocation.clearWatch(this.watchID);
    this.watchID = null;
  },

  componentDidMount() {
      // Use timer to force GPS update
      // watchPosition updates too slowly, maybe every 10 seconds
    this.setInterval(
        () => {
          this.geoWatchStop();
          this.geoWatchStart();
        }, 3000
      );
  },

+1 and ideally not what @esutton did....

Was this page helpful?
0 / 5 - 0 ratings