Skip to content

v2.0.0 (Beta 1)

Pre-release
Pre-release
Compare
Choose a tag to compare
@matt-oakes matt-oakes released this 29 Dec 10:55
· 68 commits to master since this release

Changes

  • Support for Android using the Fused Location provider.
  • New API which allows for more flexibility in the future without further breaking changes.
  • Ability to filter heading updates in the same way as locations.
  • Returns all locations to the listener, not just the latest one which can be useful for some applications.
  • Improved test coverage.

Upgrading

Configuring

Configuring the settings for location updates now happens in a single method. You supply an object with the desired values and the location provider is then configured. This allows multiple settings to be changed at once without going back and forth over the bridge.

For example, this code from v1.0.0:

RNLocation.setDistanceFilter(5.0);
RNLocation.setDesiredAccuracy("best");

Would become this in v2.0.0:

RNLocation.configure({
  distanceFilter: 5,
  desiredAccuracy: {
    ios: "best",
    android: "highAccuracy"
  }
});

Permissions

Requesting permissions has also been combined into a single method where you specify the desired permission levels for both Android and iOS. For example, this code from v1.0.0:

RNLocation.requestAlwaysAuthorization();

Would become this in v2.0.0:

RNLocation.requestPermission({
  ios: "always",
  // New Android support in v2.0.0
  android: "fine"
});

Location subscriptions

When subscribing to location updates, the listener is now given an array of locations rather than just the last one. This is useful for some apps which might want to know the history of the device location. The shape of the location object has also been changed to be flatter and easier to work with.

For example, this code from v1.0.0:

const locationSubscription = RNLocation.subscribeToLocationUpdates(location => {
  /* Example location returned
        {
          coords: {
            speed: -1,
            longitude: -0.1337,
            latitude: 51.50998,
            accuracy: 5,
            heading: -1,
            altitude: 0,
            altitudeAccuracy: -1
          },
          timestamp: 1446007304457.029
        }
        */
});

Becomes this in v2.0.0:

const locationSubscription = RNLocation.subscribeToLocationUpdates(locations => {
  const location = locations[0];
  /* Example location returned
        {
          speed: -1,
          longitude: -0.1337,
          latitude: 51.50998,
          accuracy: 5,
          heading: -1,
          altitude: 0,
          altitudeAccuracy: -1
          floor: 0
          timestamp: 1446007304457.029
        }
        */
});