문제

Previously I get an answer to the linking of an element. My next question is: how can I get the "radius" parameter of a binded circle, from the marker?

The code:

var marker = new google.maps.Marker({
  position: new google.maps.LatLng(lat,lng),
});
var circle = new google.maps.Circle({
  map: map, 
  radius: 50,
});
circle.bindTo('map', marker);
circle.bindTo('center', marker, 'position');
Array.push(marker);

I need the cirlce's radius, which binded to the Array[x] marker. Any idea? Thanks in advance!

도움이 되었습니까?

해결책

I don't think there's a way to get a bound object from an object.

What you can do is set the circle as an object on the marker

var marker = new google.maps.Marker({
  position: new google.maps.LatLng(lat,lng),
});
var circle = new google.maps.Circle({
  map: map, 
  radius: 50,
});
marker.circle = circle; // Add the circle object to the map object
circle.bindTo('map', marker);
circle.bindTo('center', marker, 'position');
Array.push(marker);

Now you can get the radius with

Array[x].circle.getRadius();

Working example

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top