Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to panTo a location? #334

Closed
SourceNova opened this issue Sep 7, 2016 · 6 comments
Closed

how to panTo a location? #334

SourceNova opened this issue Sep 7, 2016 · 6 comments

Comments

@SourceNova
Copy link

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:
<GoogleMap
ref={(map) => map.panTo({lat: 25.0112183,lng: 121.52067570000001})}
defaultZoom={12}
onClick={this.props.onMapClick}
...

your help would be much appreciated.

@Gregoor
Copy link

Gregoor commented Oct 2, 2016

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.

@tomchentw
Copy link
Owner

@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/

@rajtrivedi88
Copy link

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

@manishrana87
Copy link

Thanks @Gregoor

@manishrana87
Copy link

Thanks @JustFly1984 , for the info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants