Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Get new location and radius from Circle component in React Google Maps API

I'm using React Google Maps API package to create a map component with a circle component inside it. Here is the package from the npm registry https://www.npmjs.com/package/@react-google-maps/api.

I'm using Circle component inside a Google Map component. I set the Circle to be draggable and resizable.

I need to get the new value of center for every drag action and get the new value of radius for every resize action. In this https://react-google-maps-api-docs.netlify.app/#circle documentation, the onCenterChanged and onRadiusChanged have type of void.

So my question is how can I get the new value of center for every drag action and get the new value of radius for every resize action using this library?

Or is there any solution using the original google maps library?

Here is the code: https://codesandbox.io/s/circle-react-google-maps-api-lo9f6

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After reading again the documentation and a lot of tries, I found the solution to get the new values of location and radius from the new position/size of the Circle.

I added onLoad prop and set the circle using it. Then I printed the circle state value to check whether there were lat, lng, and radius values or not.

I found those values and here was the code.

const [ circle, setCircle ] = useState(null)

<Circle
  center={mapCenter}
  radius={radius}
  options={circleOptions}
  onLoad={(circle) => setCircle(circle)}
  onUnmount={(circle) => setCircle(null)}
  onCenterChanged={() => circle && setCircleCenter({ lat: circle['center'].lat(), lng: circle['center'].lng() })}
  onRadiusChanged={() => circle && setRadius(parseInt(circle['radius']))}
/>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!