Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getCurrentPosition(callback) {
const hasLocationPermission = await requestLocationPermission()
/* This will only be fired on Android. On Apple we can not detect when/if a
* location permission has been granted or denied. For that reason after a
* predefined period we just timeout.
*/
if (hasLocationPermission === false) {
callback({
locationAvailable: false,
error: 'Can not obtain location permission'
})
return
}
Geolocation.getCurrentPosition(
position => {
callback({
locationAvailable: true,
position
})
},
error => {
callback({
locationAvailable: false,
error: error.message,
errorCode: error.code
})
},
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 10000 }
)
}
getNearbyBars = () => {
Geolocation.getCurrentPosition(
(position) => {
this.setState(
{
latitude: position.coords.latitude,
longitude: position.coords.longitude,
},
() => {
this.searchBars();
},
);
},
error => console.log(error),
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
);
};
this.setState({ loading: true }, () => {
Geolocation.getCurrentPosition(
(position) => {
this.setState({ location: position, loading: false });
console.log(position);
},
(error) => {
this.setState({ location: error, loading: false });
console.log(error);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000, distanceFilter: 50, forceRequestLocation: true }
);
});
}
getNearbyBars = () => {
if (this.mounted) {
Geolocation.getCurrentPosition(
(position) => {
this.setState(
{
latitude: position.coords.latitude,
longitude: position.coords.longitude,
},
() => {
this.searchBars();
},
);
},
error => console.log(error),
{
enableHighAccuracy: true,
timeout: 30000,
maximumAge: 10000,
getNearbyBars = () => {
if (this.mounted) {
Geolocation.getCurrentPosition(
(position) => {
this.setState(
{
latitude: position.coords.latitude,
longitude: position.coords.longitude,
},
() => {
this.searchBars();
},
);
},
error => console.log(error),
{ enableHighAccuracy: false, timeout: 25000, distanceFilter: 0 },
);
}
};
async _findClosestBuilding(): Promise {
this.setState({ locating: true });
const locationPermissionGranted = await Permissions.requestLocationPermission(Platform.OS, PermissionsAndroid);
if (locationPermissionGranted) {
Geolocation.getCurrentPosition((position: any) => {
const location = { latitude: position.coords.latitude, longitude: position.coords.longitude };
this.setState({
closestBuilding: Navigation.findClosestBuilding(location, this.props.buildingList, MAXIMUM_DISTANCE),
locating: false,
locationError: undefined,
});
},
(err: any) => this._showLocationErrorMessage(err),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
}
}