【问题标题】:If a point is visible on the map如果某个点在地图上可见
【发布时间】:2011-08-22 15:55:18
【问题描述】:

如何知道某个点在我的地图上是否可见?

var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng)); 如果 map.getbounds().contains(point) ...

【问题讨论】:

    标签: google-maps-api-3


    【解决方案1】:

    如果通过可见,您的意思是如果一个点位于地图的可见区域(视口)内;

    // assuming you initialized your map
    
    var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
    var currentBounds = map.getBounds() // get bounds of the map object's viewport
    
    if(currentBounds.contains(point)){
        // your location is inside your map object's viewport
    }else{
        // your location is out of the bounds of the map's visible viewport
    }
    

    【讨论】:

    • 我以为 getBounds 不在 V3 中?!
    • api 参考链接现在失效了^^
    • @mtness 你在这里 :) -> ref
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 2012-07-17
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    相关资源
    最近更新 更多