最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the radius of an editable circle Google Map Api V3 on the fly? is it possible? - Stack Overflow

programmeradmin7浏览0评论
 var sunCircle = {
    strokeColor: "#c3fc49",
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: "#c3fc49",
    fillOpacity: 0.35,
    map: map,
    center: userPosition,
    radius: 1000, // in meters
    editable:true
};
cityCircle = new google.maps.Circle(sunCircle);
cityCircle.bindTo('center', marker, 'position');

Now its Editable is true we can edit the circle, can i get the radius if user changes the radius?

 var sunCircle = {
    strokeColor: "#c3fc49",
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: "#c3fc49",
    fillOpacity: 0.35,
    map: map,
    center: userPosition,
    radius: 1000, // in meters
    editable:true
};
cityCircle = new google.maps.Circle(sunCircle);
cityCircle.bindTo('center', marker, 'position');

Now its Editable is true we can edit the circle, can i get the radius if user changes the radius?

Share Improve this question asked Feb 2, 2013 at 8:37 user1796203user1796203 351 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7
google.maps.event.addListener(cityCircle, 'radius_changed', function () {
    console.log(cityCircle.getRadius());
});

You can find more info about editing events here

In React we can use ref

STEP 1: Import useRef from react library

import React, { useRef } from 'react';

STEP 2: create refCircle variable inside react ponent

let refCircle = useRef(null);

STEP 3: create handleCircleRadius inside react ponent

const handleCircleRadius = () => {
  console.log('New Radius', refCircle.getRadius());
};

STEP 4: use ref and handleCircleRadius method inside the circle ponent

<Circle
  ref={(ref) => (refCircle = ref)}
  defaultCenter={{
    lat: parseFloat(12),
    lng: parseFloat(12),
  }}
  defaultEditable={true}
  radius={parseFloat(1000)}
  center={{
    lat: parseFloat(12,
    lng: parseFloat(12),
  }}
  onRadiusChanged={handleCircleRadius}
  options={{ strokeColor: '#ff0000' }}
/>

NOTE: this circle method import from react-google-maps library

Library Link: https://www.npmjs./package/react-google-maps

OutPut

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论