Closed Tanumay92 closed 6 years ago
export default class TestPage extends Component { state = { position: {}, }; constructor(props:Object) { super(props); this.setToUserLocation().catch(error => error); } async setToUserLocation():Promise { let checkLocation = await this.checkLocation(); if (!Object.is(checkLocation, 'disabled')) { this.getLocation(); } else { this.setToUserLocation().catch(error => error); // if location services is disabled try to show dialog } } async checkLocation():Promise { return await LocationServicesDialogBox.checkLocationServicesIsEnabled({ message: 'Use Location ?', ok: 'YES', cancel: 'NO' }); } getLocation():void { navigator.geolocation.getCurrentPosition((position) => { this.setState({ position }); }, function(error) { this.getLocation(); // if no location info is received try recall }.bind(this), { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 } ); } }