Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native-Maps: How to use animateCamera and setCamera

Tags:

react-native

I am new in react native and I want to animate map on particular position i'll use animateToCoordinates that deprecated and not working sometimes.

new Method for that is animateCamera but i don't get how to use that na d how to create camera object to pass in that.

thanks

like image 279
husen Avatar asked Jul 16 '26 03:07

husen


2 Answers

You can use animateToRegion(region,duration) by simply passing the region as

let region={latitude:<Target_latitude>,longitude:<Targeted_longitude>,latitudeDelta: LATITUDE_DELTA,longitudeDelta:LONGITUDE_DELTA}

keeping Deltas fixed you can have your animation in map.

For animateToCamera you can use

    this.mapRef.animateCamera({center: temp_cordinate,pitch: 2, heading: 20,altitude: 200, zoom: 40},duration)

where type of temp_cordinate is {latitude:latitude,longitude:longitude}

like image 69
Ashish Shrestha Avatar answered Jul 17 '26 19:07

Ashish Shrestha


set ref to your mapView like this;

            <MapView
                ref={(map) => { this.map = map; }}
                initialRegion={this.state.region}
            />

then,

this.map.animateToRegion(region,1000)

call this whenever you need to update your region value

like image 25
Orhan Avatar answered Jul 17 '26 19:07

Orhan