Esri / nearby-javascript

ArcGIS API for JavaScript app to find places nearby and route to the nearest location.
Apache License 2.0
41 stars 24 forks source link

Handle geolocation errors #18

Closed andygup closed 5 years ago

andygup commented 5 years ago

Suggestion to enhance useGeolocation.ts:

Replace these lines:

      navigator.geolocation.getCurrentPosition(({ coords }) => {
        const { latitude, longitude } = coords;
        setState({ latitude, longitude });
      });

With the following:

      // Check if geolocation is enabled
      if ("geolocation" in navigator) {
        navigator.geolocation.getCurrentPosition(({ coords }) => {
          const { latitude, longitude } = coords;
          . . .  
        }, error => {
          // handle geolocation errors
          });
      } else {
        // gracefully handle in UI when no geolocation is available
      }
odoe commented 5 years ago

closed itself via new commit, but this is updated in the source now.