Releases: timfpark/react-native-location
v2.2.1
v2.2.0
Features
Added additional configuration options for Android (interval
, fastestInterval
, and maxWaitTime
). Thanks to @[naftalibeder for reporting these as missing. As an example, you can use them to get updates every 1 second:
RNLocation.configure({
desiredAccuracy: {
ios: "best",
android: "highAccuracy"
},
interval: 1000,
maxWaitTime: 1000
});
v2.1.1
Bug fixes
- Babel issues with older versions of React Native due to .bablerc being distributed via npm
v2.1.0
New Features
RNLocation.getLatestLocation
Get the latest location. Ensure you have the correct permission before calling this method.
This will subscribe to location events for you at the unsubscribe when it gets its first valid location. Usually, this method will return very fast with a possibly out of date location, however, in some circumstances, it will not return a location. Therefore, this method has a timeout after which the promise will be resolved with null
value.
The location provider will respect the settings you have given it, so if you need a location with a certain accuracy, ensure you call RNLocation.configure
first. If you want any location then ensure you call RNLocation.configure
with no distance filter.
RNLocation.configure({ distanceFilter: null });
RNLocation.getLatestLocation({ timeout: 60000 })
.then(latestLocation => {
// Use the location here
})
v2.0.2
Bug Fixes
- Fix an Android crash by using a lower request code when attempting to resolve Google Play Service errors.
v2.0.1
- [Fix] Add the required package.json properties to allow installing with Cocoapods to work
v2.0.0
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.
- Add Cocoapods support for iOS.
- 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
}
*/
});
v2.0.0 (Beta 1)
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
}
*/
});
v1.0.0
Changes
- Support newer versions of React Native. It should support from React Native 0.46 and above, however, it is recommended to use the latest React Native version (0.57.5 when this was published).
- Added types to the library. These should work with both Flow and TypeScript.
- Update the library to use the
NativeEventEmitter
. See the upgrade guide below. - Updated the README with better installation instructions and a rationale for using the library.
Upgrading
The API for listening to events has been changed. You now need to import the RNLocationEventEmitter
from the library and then call addListener
on that object.
For example:
import RNLocation, { RNLocationEventEmitter } from 'react-native-location';
RNLocation.requestAlwaysAuthorization();
RNLocation.startUpdatingLocation();
RNLocation.setDistanceFilter(5.0);
var subscription = RNLocationEventEmitter.addListener('locationUpdated', (location) => {
// TODO: Implement
});