In the last post
(JS Geolocation API – Get a User's Location)
we have covered navigator.geolocation.getCurrentPosition()
method to get user's location. We have used the success and error callbacks to
receive the position object or report error.
The method getCurrentPosition()
also accepts an options
object as third paramter (optional).
This options
object allows you to specify:
-
enableHighAccurancy
(default false): if set to true, response is slower and more accurate. -
maximumAge
(default 0): milliseconds when cached value is valid, the device may decide to use valid cached data instead of sensor measure. Represents age for the returned position value (up until this age it will be cached and reused if the same position is requested again, after this the browser will request fresh position data) -
timeout
(default infinity): milliseconds before the API gives up and calls the error handler (the second parameter).
The example below calls getCurrentPosition()
with both success and error callbacks, and pass the options
object in third argument:
var options = { enableHighAccuracy: true, timeout: 5000, //timeout 5 seconds maximumAge: 10000 //(location) age 10 seconds }; navigator.geolocation.getCurrentPosition(success, error, options);
Thanks for sharing blog with us.
ReplyDeletehttps://sixphrase.com/
https://sixphrase.com/about/
https://sixphrase.com/data-structure-algorithm-expert/
Thanks for sharing this content
ReplyDeleteB Des Interior Design Colleges in Tamilnadu
Thanks for sharing this content
ReplyDeletetop 10 mba logistics colleges in tamilnadu