【问题标题】:Google Maps v3 map.getBounds().containsLatLng is not a functionGoogle Maps v3 map.getBounds().containsLatLng 不是函数
【发布时间】:2012-06-09 14:42:14
【问题描述】:

如何在此处设置“setMap”函数以将此代码移植到 v3?或者一般将其移植到 v3...

// 地图重新定位,如果元素在地图屏幕之外

while ((!map.getBounds().containsLatLng(marker.getPosition())) & (showAllCategoryElements == 0)) {
        var newCenterPointLng = (map.getBounds().getCenter().lng() + marker.getPosition().lng()) / 2;
        var newCenterPointLat = (map.getBounds().getCenter().lat() + marker.getPosition().lat()) / 2;
        map.panTo(new google.maps.LatLng(newCenterPointLat, newCenterPointLng));
        map.setCenter(new google.maps.LatLng(newCenterPointLat, newCenterPointLng));
        if (!map.getBounds().containsLatLng(marker.getPosition())){
            map.zoomOut();
        }

这是一个例子http://d.hatena.ne.jp/tsmsogn/20111216/1324026723 一些提示:markus.tao.at/geo/google-maps-api-v3-is-in-town/

我还导入https://github.com/tparkin/Google-Maps-Point-in-Polygon js 以获得“containsLatLng”支持

感谢您的帮助或提示

【问题讨论】:

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


    【解决方案1】:

    根据 API 文档,.getbounds() 返回 google.maps.LatLngBounds 而不是 maps.Polygon。

    你不需要额外的导入,因为 LatLngBounds 有一个包含函数。

    map.getBounds().contains(marker.getPosition()) ....
    

    https://developers.google.com/maps/documentation/javascript/reference#LatLngBounds

    【讨论】:

      【解决方案2】:

      在 Google 地图 v3 中,我们有另一种方法。 这是最适合您的例子。 https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation

      【讨论】:

        猜你喜欢
        • 2012-12-20
        • 1970-01-01
        • 2014-12-23
        • 2012-07-17
        • 2021-06-26
        • 2016-01-09
        • 2013-06-21
        • 2013-04-03
        • 1970-01-01
        相关资源
        最近更新 更多