DEV Community


Posted on

How to Animate pointer on Google Map in React Native

This article is to show animation of pointer movement on Google map.
There are many ways of doing an animation of pointer movement on maps ,this article focus on using the react-native-maps.We use MapView, Marker and AnimatedRegion for this animation.

Here's what we'll create at the end of this article :

Pointer Animation

For creating this animation we use the location array which has latitude and longitude values ,for example :
{latitude: 20.93289777777778,longitude:77.77506666666666}

We will update the location in state every 4 sec, so we will get the next pointer value and animate it on Map.

Code sample:

const [location  ,setlocation ]=useState(0); 

 useEffect(() => {                
        const interval = setInterval(() => { 

        return () => clearInterval(interval)       

const getLocation =  () => {   
        console.log("get live location after 4 second")
let i=0; 
var locationArray=[             
const { latitude, longitude } =locationArray[i+1];
animate(latitude, longitude);

const animate = (latitude, longitude) => {
        const newCoordinate = {latitude, longitude};
        if(Platform.OS == 'android'){
            markerRef.current.animateMarkerToCoordinate(newCoordinate, 7000);
Enter fullscreen mode Exit fullscreen mode

The Complete code is available on

Top comments (0)