Reputation: 771
I have integrated react native map with my latest react native application.In the map i want to set boundaries to the map. The official document suggests the method
setMapBoundaries
but it requires the argument like this northEast: LatLng, southWest: LatLng
.
How can i get the values for these arguments.my mapView is like this.
<MapView
showsUserLocation
provider={MapView.PROVIDER_GOOGLE}
style={styles.map}
region={region}
onRegionChangeComplete={this.onRegionChangeComplete}
setMapBoundaries={}
onUserLocationChange={this.onUserLocationChange}
>
Upvotes: 2
Views: 4496
Reputation: 472
const onRegionChange = async (region) => {
const bound = await mapRef.current.getMapBoundaries().then((response) => {
return response;
}) -> you can pass this value
await mapRef.current.setMapBoundaries({latitude: your custom value,longitude: your custom value},{latitude: your custom value,longitude: your custom value}); -> you can pass your custom north-east and south-west coordinate too
};
<MapView
ref={mapRef}
onRegionChange={onRegionChange}
Upvotes: 1
Reputation: 2770
What you are trying to use is not a property
or event
, it's a method
. So you can't use it there. Check the documentation again.
setMapBoundaries(northEast: LatLng, southWest: LatLng): void;
export interface LatLng {
latitude: number;
longitude: number;
}
Try to get the ref
of the MapView,
<MapView
ref={(ref)=> this.mapRef = ref}
/>
and call the method setMapBoundaries
this.mapRef.setMapBoundaries({latitude: 1, longitude: 1},{latitude: 1, longitude: 1})
Upvotes: 6