({ onSuccess, onError = () => { } })
| 29 | * @return {number} |
| 30 | */ |
| 31 | const trackLocation = ({ onSuccess, onError = () => { } }) => { |
| 32 | if ('geolocation' in navigator === false) { |
| 33 | return onError(new Error('Geolocation is not supported by your browser.')); |
| 34 | } |
| 35 | |
| 36 | return navigator.geolocation.watchPosition(onSuccess, onError, { |
| 37 | enableHighAccuracy: true, |
| 38 | timeout: 5000, |
| 39 | maximumAge: 0 |
| 40 | }); |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Get position error message from the given error code. |