Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
The browser shows a permission prompt when you first request the position. If the user denies it, handle the error by passing an error callback as the second argument to getCurrentPosition() or watchPosition().
navigator.geolocation.getCurrentPosition(position => {
console.log(position)
}, error => {
console.error(error)
})
The error object has a code property that indicates the error type:
1means permission denied2means position unavailable3means timeout
Lessons in this unit:
| 0: | Introduction |
| 1: | Getting the user's position |
| 2: | Watching the position for changes |
| 3: | ▶︎ If the user denies the position |
| 4: | Adding more options |