Google maps 谷歌地图检查地图边界中是否存在圆圈边界

Google maps 谷歌地图检查地图边界中是否存在圆圈边界,google-maps,Google Maps,我有一张谷歌地图,上面有一个圆圈 我想知道当前是否可以在用户正在查看的位置范围内查看圆 到目前为止,我发现的是检查地图的中心是否在边界内,但我想检查整个地图,而不仅仅是它的中心 检查当前地图中心是否在圆边界内的我的代码: google.maps.event.addListener(map, 'bounds_changed', function() { var circleBo

我有一张谷歌地图,上面有一个圆圈

我想知道当前是否可以在用户正在查看的位置范围内查看圆

到目前为止,我发现的是检查地图的中心是否在边界内,但我想检查整个地图,而不仅仅是它的中心

检查当前地图中心是否在圆边界内的我的代码:

            google.maps.event.addListener(map, 'bounds_changed', function() 
            {                    
                var circleBounds = circle.getBounds();
                // Log into the console whether the center is inside or outside
                console.log( circleBounds.contains( map.getCenter() ) );
            });
所以我想要的是这样的东西,当然这是不正确的:

circleBounds.contains( map.getBounds() )
  • 确定圆的最北端、最南端、最西端和最东端的纬度。给定圆的半径,你可以找到这个

  • 确定所有点是否都在视口边界内

  • 如果为真,则为是,圆圈必须可见

  • 你真的应该回到你以前的问题并接受它们(点击最佳答案旁边的复选框)。这就是你对回答者辛勤工作的感激之情。

    谢谢蒂娜·霍尔

    以防其他人需要,我的问题代码如下:

    // Get the bounds
    var circleBounds = circle.getBounds();      
    var ne = circleBounds.getNorthEast(); // LatLng of the north-east corner
    var sw = circleBounds.getSouthWest();
    var nw = new google.maps.LatLng(ne.lat(), sw.lng());
    var se = new google.maps.LatLng(sw.lat(), ne.lng());
    
    google.maps.event.addListener(map, 'bounds_changed', function() 
    {                    
        var mapBounds = map.getBounds();
    
        // Log whether the circle is inside or outside of the map bounds
        if(mapBounds.contains(ne))
        {
            console.log("northeast is viewable");
        }
        if(mapBounds.contains(sw))
        {
            console.log("southwest is viewable");
        }
        if(mapBounds.contains(nw))
        {
            console.log("northwest is viewable");
        }
        if(mapBounds.contains(se))
        {
            console.log("southeast is viewable");
        }
    });
    

    这是一个老生常谈的问题——互联网时代的恐龙——但如果你比较两个界限,那么下面的问题就更重要了,n'est-ce pas?:

    这是因为对于矩形R,SW是(
    max(x),min(y)
    );NE是(
    min(x),max(y)
    )-因此R中的所有(
    x,y
    )都包含在测试中


    我当然希望是这样——这是我做所有边界比较的方式……

    他说他想检查地图是否在圆圈内,而不是圆圈是否在地图内。对我来说没什么意义,但我知道什么
    if(a.getBounds().contains(b.getBounds().getNorthEast()) 
    && a.getBounds().contains(b.getBounds().getSouthWest()))
    {console.log('B is within A... Bounds are RECTANGLES: \
                  You only need to test two \ 
                  diagonally-opposing corners')};