diff --git a/i18n/en-US.yml b/i18n/en-US.yml index 613156575..8c438529b 100644 --- a/i18n/en-US.yml +++ b/i18n/en-US.yml @@ -34,8 +34,14 @@ actions: setPaymentError: "Error setting payment info:" setRequestStatusError: "Error setting request status:" location: + deniedAccessAlert: > + Access to your location is blocked. + + To use your current location, enable location permissions from your + browser, and reload the page. geolocationNotSupportedError: Geolocation not supported by your browser unknownPositionError: Unknown error getting position + userDeniedPermission: User denied permission map: currentLocation: (Current Location) user: diff --git a/i18n/fr.yml b/i18n/fr.yml index 742db4275..5c41e72fc 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -38,8 +38,14 @@ actions: setPaymentError: "Erreur sur les coordonnées de paiement :" setRequestStatusError: "Erreur sur l'état de la requête :" location: + deniedAccessAlert: > + L'accès à votre position est refusé. + + Pour utiliser votre emplacement actuel, permettez-en l'accès depuis votre + navigateur, et ouvrez de nouveau cette page. geolocationNotSupportedError: La géolocalisation n'est pas prise en charge par votre navigateur. unknownPositionError: Erreur inconnue lors de la détection de votre emplacement. + userDeniedPermission: Refusé par l'utilisateur map: currentLocation: (Emplacement actuel) user: @@ -178,7 +184,7 @@ components: AdvancedOptions: bannedRoutes: Choisissez les lignes à éviter… bikeTolerance: Tolérance au vélo - preferredRoutes: Choisissez les lignes preferées + preferredRoutes: Choisissez les lignes préferées walkTolerance: Tolérance à la marche AfterSignInScreen: mainTitle: Redirection... diff --git a/lib/actions/location.tsx b/lib/actions/location.tsx index a336efb18..c62e9b740 100644 --- a/lib/actions/location.tsx +++ b/lib/actions/location.tsx @@ -2,6 +2,7 @@ import { createAction } from 'redux-actions' import { Dispatch } from 'redux' import { IntlShape } from 'react-intl' +import { isMobile } from '@opentripplanner/core-utils/lib/ui' import { setLocationToCurrent } from './map' @@ -47,9 +48,29 @@ export function getCurrentPosition( // On error (error) => { console.log('error getting current position', error) - // FIXME, analyze error code to produce better error message. - // See https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError - dispatch(receivedPositionError({ error })) + // On desktop, after user clicks "Use location" from the location fields, + // show an alert and explain if location is blocked. + // TODO: Consider moving the handling of unavailable location to the location-field component. + if (!isMobile() && error.code === 1) { + window.alert( + intl.formatMessage({ + id: 'actions.location.deniedAccessAlert' + }) + ) + } + const newError = { ...error } + if (error.code === 1) { + // i18n for user-denied location message (error.code = 1 on secure origins). + if ( + window.location.protocol === 'https:' || + window.location.host.startsWith('localhost:') + ) { + newError.message = intl.formatMessage({ + id: 'actions.location.userDeniedPermission' + }) + } + } + dispatch(receivedPositionError({ error: newError })) }, // Options { enableHighAccuracy: true } diff --git a/lib/components/app/responsive-webapp.js b/lib/components/app/responsive-webapp.js index e135c16b1..0ae74b8a7 100644 --- a/lib/components/app/responsive-webapp.js +++ b/lib/components/app/responsive-webapp.js @@ -153,11 +153,9 @@ class ResponsiveWebapp extends Component { } } - // Test location availability on load, - // so it is reported correctly by the location fields. - getCurrentPosition(intl) - if (isMobile()) { + // Test location availability on load + getCurrentPosition(intl) // Also, watch for changes in position on mobile navigator.geolocation.watchPosition( // On success