React-google-maps: how to panTo a location?

Created on 7 Sep 2016  Â·  6Comments  Â·  Source: tomchentw/react-google-maps

Hi,
I can't use the functions you mad public in the GoogleMap component. For example:
panTo(latLng) { return (this.props.map || this.refs.delegate).panTo(latLng); }

when i try to use panTo on the ref of the map, i get this Error:
TypeError: map.panTo is not a function

my code:
ref={(map) => map.panTo({lat: 25.0112183,lng: 121.52067570000001})}
defaultZoom={12}
onClick={this.props.onMapClick}
...

your help would be much appreciated.

Most helpful comment

try

ref={(map) => map && map.panTo({lat: 25.0112183,lng: 121.52067570000001})}

ref may be called when the element is not yet mounted, hence the method wouldn't be available then.

All 6 comments

try

ref={(map) => map && map.panTo({lat: 25.0112183,lng: 121.52067570000001})}

ref may be called when the element is not yet mounted, hence the method wouldn't be available then.

@Gregoor Thanks for answering. Please read the documentation about ref: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute

Also, 6.0.0 is released on npm beta tag now. We also have a new demo page. Feel free to try it:
https://tomchentw.github.io/react-google-maps/

Thank You @Gregoor...saved lot of hours.

Thanks @Gregoor

Thanks @JustFly1984 , for the info

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manoj150283 picture manoj150283  Â·  3Comments

MrSaints picture MrSaints  Â·  3Comments

julienvincent picture julienvincent  Â·  3Comments

timkraut picture timkraut  Â·  3Comments

bansalvks picture bansalvks  Â·  3Comments