geolocation - React-Native 地理定位中的超时和maximumAge是什么

标签 geolocation react-native react-native-ios

我目前正在学习 react-native,并且我正在开发一个使用 Geolocation 来查找和更新我当前位置的应用程序,我正在按照教程进行操作,并且在教程中我必须使用具有 timeoutma​​ximumAge 选项。

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})

但是没有解释timeoutma​​ximumAge是什么意思,我们为什么要用它们。

我知道这些选项在 react-native 提供的两种方法中使用:getCurrentPosition(调用最新位置的回调)和 watchPosition(每当位置发生变化时调用回调)但我不明白它们是什么准确地做。

最佳答案

我问过教程的作者,他的回答是:

超时:是一个正值,表示允许设备返回位置的最长时间。

MaximumAge:是一个正值,表示可接受返回的可能缓存位置的最长存在时间(以毫秒为单位)。换句话说,在我开始获取要返回的当前位置之前缓存的位置可以保留多久。

关于geolocation - React-Native 地理定位中的超时和maximumAge是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45167315/

相关文章:

iOS 如何知道我正在穿越特定位置

javascript - React Native Maps FlatList scrollToIndex() 不是函数/未定义

javascript - 注册 Amazon Web Service Cognito 错误 InvalidParameterException

android - 使用 RxJS 响应 native

android - AutoCompleteTextView 在 React Native 中与 iOS 和 Android 兼容

reactjs - rn-fetch-blob 错误 : RNFetchBlob. fetchBlobForm 未能创建请求正文

python - 将 Sentinel-1 SAR 图像的像素位置转换为地理坐标(纬度、经度)

geolocation - 分部/区域的 FIPS 到 ISO 3166 代码

ios - 参数列表太长 : recursive header expansion failed

android - Android phonegap GPS 精度