Google-map-react: Marker animations

Created on 11 Oct 2016  Â·  4Comments  Â·  Source: google-map-react/google-map-react

Hello,

is there an easy way to animate markers when loading the map for the first time ? Is it possible to use standard Google Maps Marker Animations when using own components as markers ?

For example, when creating markers you would usually do:

marker = new google.maps.Marker({
  map: map,
  animation: google.maps.Animation.DROP,
  position: { lat: 59.327, lng: 18.067 }
});

Thanks !

Most helpful comment

You can access the Google API by using onGoogleApiLoaded in the GoogleMap component:

<GoogleMap bootstrapURLKeys={{key: APIKEY}} onGoogleApiLoaded={this.initMap} />

Then you can write a method in your react componet:

initMap({map, maps}) {
    var marker = new maps.Marker({
        map: map,
        animation: maps.Animation.DROP,
        position: {lat: -27.63453, lng: 153.0387}
    })
}

The objects {map, maps} in the callback function gives you access to:
maps -> Animation, ControlPosition, MapTypeControlStyle, MapTypeId, ...
map -> qg {gm_bindings_: Object, __gm: rf, gm_accessors_: Object, streetViewControl: true…

All 4 comments

You can access the Google API by using onGoogleApiLoaded in the GoogleMap component:

<GoogleMap bootstrapURLKeys={{key: APIKEY}} onGoogleApiLoaded={this.initMap} />

Then you can write a method in your react componet:

initMap({map, maps}) {
    var marker = new maps.Marker({
        map: map,
        animation: maps.Animation.DROP,
        position: {lat: -27.63453, lng: 153.0387}
    })
}

The objects {map, maps} in the callback function gives you access to:
maps -> Animation, ControlPosition, MapTypeControlStyle, MapTypeId, ...
map -> qg {gm_bindings_: Object, __gm: rf, gm_accessors_: Object, streetViewControl: true…

Thanks for your quick response - this helps me a lot. Thanks ! :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings