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

use getCenter function and others #466

Closed
alex-brain opened this issue Apr 19, 2017 · 11 comments
Closed

use getCenter function and others #466

alex-brain opened this issue Apr 19, 2017 · 11 comments

Comments

@alex-brain
Copy link

alex-brain commented Apr 19, 2017

How can I use getCenter?
I try
<GoogleMap
defaultZoom={14}
center={{lat: props.mapCenter.lat, lng: props.mapCenter.lng}}
onCenterChanged={getCenter()}

But I get message getCenter is undefined

@tomchentw
Copy link
Owner

Please refer to Getting Help section in the README (or #469).

@tomchentw
Copy link
Owner

tomchentw commented Apr 26, 2017 via email

@tomchentw
Copy link
Owner

It's defined in the public method of the <GoogleMap> component. So get the ref and call getBounds
https://github.com/tomchentw/react-google-maps/blob/master/src/lib/GoogleMap.js#L97

@jkranking
Copy link

Can anyone explain how to properly access the refs and how to subsequently call a function off of it per DavidVaini's question above?

@Y-Taras
Copy link

Y-Taras commented May 6, 2017

here's a nice example from official documentation
https://tomchentw.github.io/react-google-maps/places/search-box

@Pegahkeshavarz
Copy link

none of these examples are working?

@tomchentw
Copy link
Owner

@Pegahkeshavarz
Copy link

Pegahkeshavarz commented Nov 8, 2017

I am trying to get the center info by clicking on a button but when using this.refs.map.getCenter() i am getting the error of can not find property getCenter of undefined?

@tomchentw
Copy link
Owner

You need to store ref in some way so that they can access it later.

@Darksoulsong
Copy link

This is how I'm trying to use getCenter using a ref, and it's not working.

const Map = withScriptjs(
  withGoogleMap(() => {
    const ref: any = useRef<HTMLElement>(null);

    return (
      <GoogleMap
        options={{
          styles: mapOptions.styles,
          scrollwheel: mapOptions.scrollwheel
        }}
        defaultZoom={mapOptions.zoom}
        defaultCenter={{ lat: -26.896333, lng: -49.23524 }}
        ref={ref}
      >
        <Marker position={ref.current.getCenter()} />
      </GoogleMap>
    );
  })
);

@JustFly1984
Copy link

@Darksoulsong this repo is unmaintained more than a year, please refer to npm @react-google-maps/api

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

7 participants