0

I have a problem with this lib. I am trying to get the current center coordinate from the map by (onPress), but none to display,

agree = async () => {
  const center = await this._map.getCenter();
  console.warn(center);
}

the map code.

<MapboxGL.MapView
  ref={(c) => this._map = c}
  style={{ flex: 1 }}
  zoomLevel={15}
  centerCoordinate={[-122.084, 37.422]}>
</MapboxGL.MapView>

and I am using onPress like this:

<TouchableOpacity
  style={styles.button}
  onPress={this.agree.bind(this)}
>
  <Text style={styles.buttonText}>NYC</Text>
</TouchableOpacity>

Any Help?

Subhendu Kundu
  • 3,618
  • 6
  • 26
  • 57

1 Answers1

0

I have done like(using navigator) :

getCurrentLocation = () => {
        navigator.geolocation.getCurrentPosition((pos) => {
            console.log("lng:"+pos.coords.longitude + "lat:"+pos.coords.latitude); 
            //goto your current location 
            this._map.setCamera({
                centerCoordinate: [pos.coords.longitude, pos.coords.latitude],
                zoom: 17
            });
        });
    }

Official docs : link

Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52