@@ -370,24 +370,41 @@ export default function DriveBCMap(props) {
370370 const [ showLocationAccessError , setShowLocationAccessError ] = useState ( false ) ;
371371
372372 const loadMyLocation = ( ) => {
373- // per DBC22-5228, clicking button always moves to user's current location
374- if ( 'geolocation' in navigator ) {
375- navigator . geolocation . getCurrentPosition ( ( position ) => {
376- const { latitude, longitude } = position . coords ;
377- if (
378- position . coords . longitude <= - 113.7 &&
379- position . coords . longitude >= - 139.3 &&
380- position . coords . latitude <= 60.1 &&
381- position . coords . latitude >= 48.2
382- ) {
383- setZoomPan ( mapView , 9 , fromLonLat ( [ longitude , latitude ] ) ) ;
384- }
385- } ) ;
386- }
387-
388373 if ( ! locationSet . current ) {
389374 setMyLocationLoading ( true ) ;
390375 } else {
376+ // per DBC22-5228, clicking button always moves to user's current location
377+ if ( 'geolocation' in navigator ) {
378+ navigator . geolocation . getCurrentPosition (
379+ ( position ) => {
380+ const { latitude, longitude } = position . coords ;
381+ if (
382+ position . coords . longitude <= - 113.7 &&
383+ position . coords . longitude >= - 139.3 &&
384+ position . coords . latitude <= 60.1 &&
385+ position . coords . latitude >= 48.2
386+ ) {
387+ setZoomPan ( mapView , 9 , fromLonLat ( [ longitude , latitude ] ) ) ;
388+ }
389+ } ,
390+ ( error ) => {
391+ // The user has blocked location access
392+ if ( error . code === error . PERMISSION_DENIED ) {
393+ setShowLocationAccessError ( true ) ;
394+ setMyLocationLoading ( false ) ;
395+
396+ } else {
397+ // Zoom out and center to BC if location not available
398+ setZoomPan ( mapView , 9 , fromLonLat ( [ - 126.5 , 54.2 ] ) ) ;
399+ setMyLocationLoading ( false ) ;
400+ }
401+ } ,
402+ {
403+ maximumAge : 30000 , // 30 seconds
404+ }
405+ ) ;
406+ }
407+
391408 dispatch ( updateSearchLocationFromWithMyLocation ( [ locationSet . current ] ) ) ;
392409 }
393410 }
0 commit comments