开发者

Get a parameter from a binded element in Google Maps

开发者 https://www.devze.com 2023-01-23 21:37 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消