Google Maps v3 map.getBounds().containsLatLng is not a function

£可爱£侵袭症+ 提交于 2019-12-01 05:49:05

问题


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


回答1:


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




回答2:


In Google maps v3 we have another metho. Here is the best example for you. https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation



来源:https://stackoverflow.com/questions/10899711/google-maps-v3-map-getbounds-containslatlng-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!