【问题标题】:React Native Mapbox gl Initial Center CoordinatesReact Native Mapbox gl初始中心坐标
【发布时间】:2017-01-08 17:21:53
【问题描述】:

所以我试图为 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 hub 页面-https://github.com/mapbox/react-native-mapbox-gl

【问题讨论】:

    标签: ios react-native mapbox mapbox-gl react-native-mapbox-gl


    【解决方案1】:

    在你的构造函数中尝试:

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

    还有:

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

    【讨论】:

      【解决方案2】:

      根据docs,值应该是一个数组

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

      【讨论】:

        【解决方案3】:

        试试这个:

        <MapboxGL.MapView
          key='mainmap'
          style={{ flex: 1 }}>
        
           <MapboxGL.Camera
             zoomLevel={2}
             centerCoordinate={[2.21, 46.22]}/>
        
        <MapboxGL.MapView />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-08-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-01-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多