Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-google-maps marker animation

Is there a way to animate a marker on react-google-maps from another component outside the maps? My specific requirement is to be able to click on an item in a list that animates the marker on the map for two seconds. It would be good to not have to re-render the markers.

like image 313
Vijay Avatar asked Aug 25 '17 17:08

Vijay


People also ask

How do I animate a marker on Google Maps?

If you want to animate marker back-and-forth, just toggle setPosition each second. setTimeout(function() { var newPosition = /* select new position */ marker. setPosition(newPosition) }, 1000);

How do you move a marker smoothly?

There is a method makeMarker() you just need to call from onMapReady() method . There is two method rotateMarker() and moveVechile() to rotate and move marker. Hope this will help you.

How to implement Google Maps in react with Google API?

Go to the Google Cloud Platform Console. Now click on create a new project, and create a new project. 4. Now click on create credentials and save it. 5. Now just copy your API key and use it in your React Project. 1. Installation We’ve installed a third-party library react-google-map in our project. Now we are good at implementing maps. 2.

Should I use React-Mapbox-GL or Google Maps?

I prefer Mapbox over Google Maps for a few reasons, mainly that I find it more performant. The following examples will be using React and a third party NPM module, react-mapbox-gl. You can do all the same using vanilla JS and your view library of choice. Once we have our map set up and rending, we can create our animated marker.

What is Google-map-react?

Failed to load latest commit information. google-map-react is a component written over a small set of the Google Maps API. It allows you to render any React component on the Google Map. It is fully isomorphic and can render on a server. Additionally, it can render map components in the browser even if the Google Maps API is not loaded.

How to integrate Google Cloud Platform with React Native?

Customization of markers. Now let’s start the integration process. Go to the Google Cloud Platform Console. Now click on create a new project, and create a new project. 4. Now click on create credentials and save it. 5. Now just copy your API key and use it in your React Project. 1. Installation


1 Answers

animation prop should be a number from 1 or 2.

1 is equal to window.google.maps.Animation.BOUNCE.

2 is equal to window.google.maps.Animation.DROP.

so to create a marker with animation it should be as following:

<Marker
position={position}
animation={window.google.maps.Animation.DROP}
/>

or

<Marker
position={position}
animation={2}
/>

And if you want to remove the BOUNCE animation use animation={null}.

You can start your app with marker state={ animation : 2 }(DROP animation) then change to state={ animation: 1 } using setState({ animation : 1 })(BOUNCE animation) and you can stop the BOUNCE animation using setState({ animation: null })

Check this Marker animation example on google maps docs

like image 141
Ahmed Mokhtar Avatar answered Oct 10 '22 01:10

Ahmed Mokhtar