diff --git a/mobile/src/Home/Home.js b/mobile/src/Home/Home.js index aa5643f..74e0aaf 100644 --- a/mobile/src/Home/Home.js +++ b/mobile/src/Home/Home.js @@ -47,7 +47,6 @@ export class Home extends React.Component { workItemDistance: -1, } - this.positionInfo = null this.watchId = null if (Platform.OS !== "ios") { @@ -69,7 +68,6 @@ export class Home extends React.Component { PermissionsAndroid.RESULTS.GRANTED ) { this.setState({ haveLocationPermission: true }) - navigator.geolocation.getCurrentPosition(this.handlePositionChange) } if ( @@ -96,7 +94,6 @@ export class Home extends React.Component { } else { this.state.haveLocationPermission = true this.state.haveCameraPermission = true - navigator.geolocation.getCurrentPosition(this.handlePositionChange) } api @@ -145,11 +142,6 @@ export class Home extends React.Component { this.setState({ messageModal: null }) } - @autobind - handlePositionChange(positionInfo) { - this.positionInfo = positionInfo - } - @autobind handleMarkerPress(e, sectionIndex) { if (this.sectionList) { @@ -160,8 +152,8 @@ export class Home extends React.Component { }) } - if (this.positionInfo) { - const coords = this.positionInfo.coords + navigator.geolocation.getCurrentPosition((positionInfo) => { + const coords = positionInfo.coords const workItem = this.state.sections[sectionIndex] const { latitude, longitude } = workItem.coordinate @@ -174,20 +166,18 @@ export class Home extends React.Component { "K" ).toFixed(2), }) - } + }) } @autobind handleWorkItemsListPress() { - if (this.positionInfo) { - const { coords } = this.positionInfo + navigator.geolocation.getCurrentPosition((positionInfo) => { + const { coords } = positionInfo this.props.history.push( `/workItemList?latLng=${coords.latitude},${coords.longitude}` ) - } else { - this.props.history.push("/workItemList") - } + }) } @autobind @@ -215,46 +205,49 @@ export class Home extends React.Component { @autobind handleGlassesPress() { const { sections: workItems } = this.state - const { - latitude: latitude1, - longitude: longitude1, - } = this.positionInfo.coords - let closestWorkItem = config.alwaysShowWorkItemInAR ? workItems[0] : null - let shortestDistance = config.minDistanceToItem - workItems.forEach((workItem) => { - const { latitude: latitude2, longitude: longitude2 } = workItem.coordinate - const distance = - geoDistance(latitude1, longitude1, latitude2, longitude2, "K") * 1000 + navigator.geolocation.getCurrentPosition((positionInfo) => { + const { latitude: latitude1, longitude: longitude1 } = positionInfo.coords + let closestWorkItem = config.alwaysShowWorkItemInAR ? workItems[0] : null + let shortestDistance = config.minDistanceToItem - if (distance <= shortestDistance) { - closestWorkItem = workItem - shortestDistance = distance - } + workItems.forEach((workItem) => { + const { + latitude: latitude2, + longitude: longitude2, + } = workItem.coordinate + const distance = + geoDistance(latitude1, longitude1, latitude2, longitude2, "K") * 1000 + + if (distance <= shortestDistance) { + closestWorkItem = workItem + shortestDistance = distance + } + }) + + this.props.history.push( + `/arviewer${ + closestWorkItem + ? "?workItemId=" + + closestWorkItem._id + + "&workItemType=" + + closestWorkItem.workItemType + : "" + }` + ) }) - - this.props.history.push( - `/arviewer${ - closestWorkItem - ? "?workItemId=" + - closestWorkItem._id + - "&workItemType=" + - closestWorkItem.workItemType - : "" - }` - ) } @autobind handleMyLocationPress() { - if (this.positionInfo) { - const coords = this.positionInfo.coords + navigator.geolocation.getCurrentPosition((positionInfo) => { + const coords = positionInfo.coords this.map.animateToCoordinate({ latitude: coords.latitude, longitude: coords.longitude, }) - } + }) } @autobind @@ -273,14 +266,6 @@ export class Home extends React.Component { workItemDistance, } = this.state - if (!this.watchId && haveLocationPermission) { - this.watchId = navigator.geolocation.watchPosition( - this.handlePositionChange, - null, - { distanceFilter: 10 } - ) - } - return (