【问题标题】:Get a parameter from a binded element in Google Maps从 Google 地图中的绑定元素获取参数
【发布时间】:2010-11-06 01:23:49
【问题描述】:

以前我get an answer 到一个元素的链接。我的下一个问题是:如何从标记中获取绑定圆的“半径”参数?

代码:

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);

我需要绑定到 Array[x] 标记的圆的半径。任何想法?提前致谢!

【问题讨论】:

    标签: google-maps bind geometry markermanager


    【解决方案1】:

    我认为没有办法从对象中获取绑定对象。

    你可以做的是将圆圈设置为标记上的对象

    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);
    

    现在你可以得到半径了

    Array[x].circle.getRadius();
    

    Working example

    【讨论】:

    • 好主意,解决我的问题,谢谢!简单又聪明:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2012-03-16
    相关资源
    最近更新 更多