P.L*_*and 3 geolocation react-native react-native-ios
我目前正在学习react-native,我正在开发一个使用地理定位来查找和更新我当前位置的应用程序,我正在遵循该教程,在教程中我必须使用带有超时和maximumAge选项的属性。
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})
Run Code Online (Sandbox Code Playgroud)
但它没有解释timeout和maximumAge的作用是什么意思,为什么我们要使用它们。
我知道这些选项在react-native提供的两个方法中使用:getCurrentPosition(调用最新位置的回调)和watchPosition(每当位置发生变化时调用回调),但我不明白它们到底在做什么。
我询问了教程的创建者,他回答说:
\n\n超时:是一个正值,表示允许设备返回位置的最长时间。
\n\nMaximumAge:是一个正值,表示可接受返回的可能缓存位置的最大寿命(以毫秒为单位)。换句话说,在我应该开始获取要返回的当前位置之前,缓存的位置可以存在多久。\xef\xbb\xbf
\n| 归档时间: |
|
| 查看次数: |
5553 次 |
| 最近记录: |