I am using Mapbox in React Native and the documentation of the MapboxGL.MapView object lists several methods, but I am unable to use them. For example, getVisibleBounds()
is said to work like this:
const visibleBounds = await this._map.getVisibleBounds();
I have implemented it like this:
<View style={container}>
<Mapbox.MapView
ref={mapRef}
styleJSON={JSON.stringify(defaultStyle)}
zoomLevel={16}
centerCoordinate={[lat, lng]}
onRegionDidChange={onRegionDidChange}
style={{ flex: 1 }}
>
</Mapbox.MapView>
</View>
The onRegionDidChange
function is defined as:
const mapRef = useRef();
const onRegionDidChange = async () => {
try {
const currentBounds = await mapRef.getVisibleBounds();
console.log(currentBounds);
} catch (error) {
console.warn(error);
}
};
Doing this gives: mapRef.getVisibleBounds is not a function.
The map itself works fine, I guess I am just unsure of the correct way to use the function. I have also tried using this._map.getVisibileBounds()
, but this gives:
undefined is not an object (evaluating '_this.map.getVisibleBounds')
I have seen similar questions asked on here and Github, however they are either unanswered or outdated.