Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raise an error when call function with invalid arguments', () => {
// $ExpectError: need an object
getCurrentPositionAsync(11);
// $ExpectError: `__accuracy` is missing in enum
getCurrentPositionAsync({ __accuracy: 1 });
});
});
it('should passes when used properly', () => {
getCurrentPositionAsync({
accuracy: Accuracy.High,
}).then(result => {
const { coords, timestamp } = result;
(timestamp: number);
(coords.latitude: number);
(coords.speed: number);
// $ExpectError: check any
(coords.speed: string);
});
});
Permissions.LOCATION
);
let finalStatus = existingStatus;
// ask again to grant locaton permissions (if not already allowed)
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
finalStatus = status;
}
// still not allowed to use location?
if (finalStatus !== 'granted') {
return;
}
const { coords } = await Location.getCurrentPositionAsync();
this.setState({
showMap: true,
userLat: coords.latitude,
userLon: coords.longitude
});
}
return new Promise((resolve, reject) => {
Location.getCurrentPositionAsync({
enableHighAccuracy: Boolean(altitude)
}).then((resp) => {
const {coords, timestamp} = resp
const {latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed} = coords
const res = {
latitude,
longitude,
speed,
altitude,
accuracy,
verticalAccuracy: altitudeAccuracy,
horizontalAccuracy: null,
heading,
timestamp
}
success && success(res)
async snap () {
if (this.camera) {
let { uri } = await this.camera.takePictureAsync()
const location = await Location.getCurrentPositionAsync({})
this.setState({
image: uri,
location: location
})
}
}
render () {
export async function getLocationAsync(onSend) {
if (await getPermissionAsync(Permissions.LOCATION)) {
const location = await Location.getCurrentPositionAsync({})
if (location) {
onSend([{ location: location.coords }])
}
}
}
export default function locate() {
if (WEB) {
return Location.getCurrentPositionAsync({
enableHighAccuracy: false,
maximumAge: 15 * 60 * 1000
});
} else {
return Location.getLastKnownPositionAsync();
}
}