簡體   English   中英

React Native Mapbox gl 初始中心坐標

[英]React Native Mapbox gl Initial Center Coordinates

所以我試圖為 mapbox 設置我的初始中心坐標,所以它們不是 0,0。 在 api 上它說 mapbox 需要一個道具

initialCenterCoordinate object  Optional    Initial latitude/longitude the map will load at.    { latitude:0, longitude: 0 }

所以我在做

<Mapbox
    initialCenterCoordinate={latitude: 40.444328, longitude: -79.953155} .... other props/>

這在該行上給了我一個錯誤,說意外的令牌,期待}。

每當我做類似的事情

<Mapbox
    initialCenterCoordinate={{latitude: 40.444328, longitude: -79.953155}} .... other props/>

它仍然將我的初始位置設置為 0,0。 誰有想法?

編輯:鏈接到 git 中心頁面 - https://github.com/mapbox/react-native-mapbox-gl

在您的構造函數中嘗試:

this.state = {
     position : {
        latitude: 49.437090,
        longitude: 1.097456,
     }
};

和:

<MapView initialCenterCoordinate={this.state.position}> </MapView>

根據文檔,該值應該是一個數組

 <Mapbox
     initialCenterCoordinate={[40.444328, -79.953155]} .... other props/>

嘗試這個 :

<MapboxGL.MapView
  key='mainmap'
  style={{ flex: 1 }}>

   <MapboxGL.Camera
     zoomLevel={2}
     centerCoordinate={[2.21, 46.22]}/>

<MapboxGL.MapView />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM