0

我目前正在學習react-native,我正在研究一個使用地理定位來查找和更新我當前位置的應用程序,並且正在關注該教程以及教程我必須使用超時maximumAge選項的屬性。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}) 

,但它並不能說明什麼呢超時maximumAge意思,爲什麼我們使用它們。

我知道這些選項用於react-native提供的兩個方法:getCurrentPosition(調用最新位置的回調)和watchPosition(每當位置發生變化時調用回調)但我不明白是什麼他們正在做着。

+0

這是我迄今爲止發現的最好的描述[來自Mozilla網站](https://developer.mozilla。組織/ EN-US /文檔/網絡/ API/PositionOptions) – Deepank

回答

0

我要求教程的創造者,他迴應道:

超時:爲正值時,表示該設備被允許返回的位置的最長時間。

MaximumAge:是一個正值,指示返回可接受的可能緩存位置的最大時間(以毫秒爲單位)。換句話說,在我開始獲取當前位置之前,多長時間可以緩存位置。

相關問題