【问题标题】:Google Maps LatLngBounds Contains function always returns trueGoogle Maps LatLngBounds Contains 函数始终返回 true
【发布时间】:2013-01-20 06:08:16
【问题描述】:

我想在拖动另一个标记时实现对齐标记功能。

我有一个函数可以检查两个标记是否“关闭”:(从here 获得)

function arePointsNear(point1, point2) {
    var sw = new google.maps.LatLng(point2.lat() - 0.005, point2.lng() - 0.005);
    var ne = new google.maps.LatLng(point2.lat() + 0.005, point2.lng() + 0.005);
    var bounds = new google.maps.LatLngBounds(sw, ne);
    return bounds.contains(point1);
};

现在,在标记的拖动事件中,我这样做:

for (var index in allMarkers) {
    if(allMarkers[index] == marker) {
        continue;
    }

    var point1 = allMarkers[index].position;
    var point2 = marker.position;

    // This always returns true
    var isClose = arePointsNear(point1, point2);
}

我做错了吗?

【问题讨论】:

    标签: google-maps google-maps-api-3 google-maps-markers


    【解决方案1】:

    算法正在运行..问题出在我的代码中。我检查的是同一个标记的位置,而不是两个标记的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-02
      • 2023-04-11
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多