WEB-DEVELOPMENT-APPLICATIONS practice question 11 of 25

Which method retrieves periods updates about the geographic location of a user:

Full set: 131 questions
Answer options
A: getCurrentPosition
B: ClearWatch
C: GetContext
D: WatchPosition Correct answer
Correct Answer:
D. WatchPosition
Explanation

The Geolocation API's watchPosition() method is used to register a handler function that is called automatically each time the position of the device changes. This provides continuous, periodic updates about the user's geographic location, making it ideal for applications that need to track a user's movement over time. The method returns a watch ID that can be used with clearWatch() to stop receiving updates.

Why Incorrect

A. getCurrentPosition retrieves the user's location only once and does not provide continuous updates.
B. clearWatch is used to stop an existing position watch initiated by watchPosition, it does not retrieve location data.
C. getContext is not a method of the Geolocation API; it is most commonly associated with the HTML Canvas API for getting a rendering context.

References

- Mozilla Developer Network (MDN). "Geolocation API". In Web APIs. "The Geolocation.watchPosition() method is used to register a handler function that will be called automatically each time the position of the device changes." Retrieved from https://developer.mozilla.org/en-US/docs/Web/API/GeolocationAPI

- W3C. (2016, October 18). Geolocation API Specification 2nd Edition. Section 5.2, "The watchPosition() Method". "The watchPosition() method is used to register a handler function that will be called automatically each time the position of the device changes." Retrieved from https://www.w3.org/TR/geolocation-API/#watch-position

Scroll to Top