Which HTML API is used to get the user’s geographic location?
Analysis & Theory
The Geolocation API is used to get the geographical position of a user.
Which method gets the current position of the user in the Geolocation API?
A
navigator.location.get()
C
navigator.getLocation()
Analysis & Theory
`navigator.geolocation.getCurrentPosition()` is the correct method.
Which object must be used to access the Geolocation API?
Analysis & Theory
`navigator` is the object used to access geolocation methods.
What is required before a website can access geolocation data?
Analysis & Theory
User permission is always required for geolocation access for privacy reasons.
What information does the position object returned by `getCurrentPosition()` contain?
Analysis & Theory
The position object includes latitude, longitude, altitude, speed, etc.
What will happen if a browser doesn’t support the Geolocation API?
C
The script will throw an error
D
You must check with `navigator.geolocation` first
Analysis & Theory
You should check `if (navigator.geolocation)` before using the API to ensure support.
Which callback function is required for `getCurrentPosition()` to work?
D
Both success and error functions
Analysis & Theory
`getCurrentPosition()` takes a success function and optionally an error function.
Which method is used to continuously monitor the user’s location?
Analysis & Theory
`watchPosition()` watches for changes in location and updates in real-time.
How can you stop watching a user’s position after using `watchPosition()`?
B
navigator.geolocation.stop()
Analysis & Theory
Use `navigator.geolocation.clearWatch(id)` to stop location tracking.
Is geolocation available in all browsers?
A
Yes, without restriction
B
Only in mobile browsers
D
Most modern browsers support it with HTTPS and permission
Analysis & Theory
Modern browsers support Geolocation, but it requires secure context (HTTPS) and user permission.