Skip to content

Commit

Permalink
Merge pull request #1348 from opentripplanner/remove-watchposition
Browse files Browse the repository at this point in the history
remove watchPosition in favor of setInterval
  • Loading branch information
amy-corson-ibigroup authored Feb 11, 2025
2 parents 3c4e55f + 2c8af8a commit 87c1425
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ class ResponsiveWebapp extends Component {

/** Lifecycle methods **/

// Check if the position has changed enough to update the currentPosition
// (prevent constant updates in nearby view)
// .001 works out to be about 94-300 ft depending on the longitude.
positionShouldUpdate = (position) => {
const { currentPosition } = this.props
if (!currentPosition.coords) return true
const latChanged =
Math.abs(
position?.coords?.latitude - currentPosition?.coords?.latitude
) >= 0.001
const lonChanged =
Math.abs(
position?.coords?.longitude - currentPosition?.coords?.longitude
) >= 0.001

return latChanged || lonChanged
}

/* eslint-disable-next-line complexity */
componentDidUpdate(prevProps) {
const {
Expand Down Expand Up @@ -197,21 +179,10 @@ class ResponsiveWebapp extends Component {
if (isMobile()) {
// Test location availability on load
getCurrentPosition(intl)
// Watch for position changing on mobile
navigator.geolocation.watchPosition(
// On success
(position) => {
if (this.positionShouldUpdate(position)) {
receivedPositionResponse({ position })
}
},
// On error
(error) => {
console.log('error in watchPosition', error)
},
// Options
{ enableHighAccuracy: true }
)
// Update position every 30 seconds. watchPosition interferes with react-map-gl.
setInterval(() => {
getCurrentPosition(intl)
}, 30000)
}
// Handle routing to a specific part of the app (e.g. stop viewer) on page
// load. (This happens prior to routing request in case special routerId is
Expand Down

0 comments on commit 87c1425

Please sign in to comment.