Google Maps v3 map.getBounds()。containsLatLng不是一个函数 [英] Google Maps v3 map.getBounds().containsLatLng is not a function

查看:649
本文介绍了Google Maps v3 map.getBounds()。containsLatLng不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



//地图recenter,如果元素在地图画面外



<$ p ((!!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支持



感谢您的帮助或提示

解决方案

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



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

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

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


How do i set the "setMap" function here to port this code to v3? Or port it generally to v3...

// map recenter, if element is outside the mapscreen

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

here is an example http://d.hatena.ne.jp/tsmsogn/20111216/1324026723 some tips: markus.tao.at/geo/google-maps-api-v3-is-in-town/

i also import https://github.com/tparkin/Google-Maps-Point-in-Polygon js to get "containsLatLng" support

Thanks for help or tips

解决方案

Per the API documentation, .getbounds() returns a google.maps.LatLngBounds not a maps.Polygon.

You don't need the extra import as LatLngBounds has a contains function.

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

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

这篇关于Google Maps v3 map.getBounds()。containsLatLng不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆