Reputation: 6027
I am using react-native-location to get the location on android.
This package's installation documentation for android says:
The library provides two methods of getting the location on Android. The default is the builtin location manager, however, you can optionally choose to install the Fused Location library which provides more accurate and faster results.
I need to get the location on my app's startup, and decide based on that in which 'application mode' to start (each mode has a different home screen).
So, on one hand, getting the location is very important, but on the other hand I don't want the user to wait more than a fraction of a second.
My code for getting the location is:
RNLocation.configure({ distanceFilter: 0,
desiredAccuracy: 'highAccuracy' });
RNLocation.getLatestLocation({ timeout: xxx })
Based on your experience: how long will it usually take to get the location with and without the Fused Location library?
Upvotes: 1
Views: 166
Reputation: 182
Hi try the code bellow:
import GetLocation from 'react-native-get-location'
GetLocation.getCurrentPosition({
enableHighAccuracy: true,
timeout: 15000,
})
.then(location => {
console.log(location);
})
.catch(error => {
const { code, message } = error;
console.warn(code, message);
})
enableHighAccuracy: Set true to use 'fine location' (GPS) our false to use 'course location' (Wifi, Bluetooth, 3G).
timeout: The max time (in milliseconds) that you want to wait to receive a location.
if you usuning android pay attetion to this:
!-- Define ACCESS_FINE_LOCATION if you will use enableHighAccuracy=true --> uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
!-- Define ACCESS_COARSE_LOCATION if you will use enableHighAccuracy=false --> uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Upvotes: 1