0

So I am trying to set my initial center coordinates for mapbox so they are not 0,0. On the api it says mapbox expects a prop of

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

So I am doing

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

This is giving me an error on that line saying unexpected token, expecting }.

Whenever I do something like

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

It still sets my initial spot to 0,0. Anyone have any ideas?

EDIT: link to git hub page- https://github.com/mapbox/react-native-mapbox-gl

Mike M
  • 4,358
  • 1
  • 28
  • 48
wdlax11
  • 822
  • 3
  • 11
  • 29

3 Answers3

3

Try this :

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

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

<MapboxGL.MapView />
R1'
  • 490
  • 1
  • 5
  • 17
0

In your constructor try with:

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

And:

<MapView initialCenterCoordinate={this.state.position}> </MapView>
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Maxence Machu
  • 330
  • 1
  • 14
0

According to the docs the value should be an array

 <Mapbox
     initialCenterCoordinate={[40.444328, -79.953155]} .... other props/>
uokesita
  • 191
  • 1
  • 11