Reputation: 1432
I am currently learning react-native and I am working on a an application that uses Geolocation to find and update my current location and I am following a tutorial for that and in the tutorial I had to use a property with the timeout and maximumAge options.
navigator.geolocation.getCurrentPosition((pozitie)=>{
var lat = parseFloat(position.coords.latitude)
var long = parseFloat(position.coords.longitude)
// create an object with the current position taken from the geolocation chip
var initialLocation = {
latitude = lat,
longitude = long,
// Delta is the viewing angle on the location of the user
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
}
// Now we are seting initial position to the initial location
this.setState({initialPositionOnTheMap: initialLocation})
// we set the marker to the initial location and then the display follows the marker
// by using the initialLocaiton object that will receive the users current location
this.setState({positionOfTheMarker: initialLocation})
},
// make a function call if an error happens
// we make an allert that parses the error message
(error) => alert(JSON.stringify(error)),
// propertie
{enableHighAccuracy: true, timeout: 2000, maximumAge: 1000})
but it didn't explain what does timeout and maximumAge mean, why do we use them.
I know that these options are used in two methods provided by react-native: getCurrentPosition(Invokes a callback with the latest location) and watchPosition(Invokes a callback whenever the location has changed) but I don't understand what are they doing exactly.
Upvotes: 3
Views: 6029
Reputation: 1432
I have asked the creator of the tutorial, and he responded:
Timeout: is a positive value that indicates the maximum time the device is allowed to return a position.
MaximumAge: is a positive value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. In other words, how old can cached locations be before I should start getting the current location to return.
Upvotes: 5