admin管理员组文章数量:1328052
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 badges2 Answers
Reset to default 7google.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
本文标签:
版权声明:本文标题:javascript - How to get the radius of an editable circle Google Map Api V3 on the fly? is it possible? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742241929a2438890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论