谷歌地图数据库边界条目不正确或我的代码遗漏了一些东西

时间:2014-02-22 16:47:16

标签: javascript database google-maps-api-3 google-geocoder bounds

我遇到了谷歌地理编码器返回的某些国家/地区的问题。

下面的示例代码在Google数据库中查询“USA”,并使用返回的边界设置矩形以显示结果。这个矩形只覆盖了美国东南部的一部分。

返回的边界(SWlat,SWlng,NElat,NElng): ((29.321898,-95.71289100000001),(37.09024,-90.90566230000002))

可能我忽略了代码中的某些内容,任何建议或想法可能是什么?

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" 
        src="http://maps.google.com/maps/api/js?sensor=false">   
</script>

<style type="text/css">
     #map-canvas, html, body { padding: 0; margin: 0; height: 100%; }
</style>

<script type="text/javascript">
    var map, 
    geocoder = new google.maps.Geocoder() ,
    rectangle = new google.maps.Rectangle() ;

    function initialize() {
        map = new google.maps.Map (document.getElementById('map-canvas'), {
                zoom: 4,
                center: new google.maps.LatLng(40, -95)
        });         

        geocoder.geocode( {'address': 'USA'}, function(results, status){
             if (status == 'OK') {
                 rectangle.setBounds (results[0]["geometry"]["bounds"]) ;
                 rectangle.setMap (map);
                 console.log ( rectangle.getBounds().toString() );
             }
        }); 
    }

    google.maps.event.addDomListener(window, 'load', initialize);   

</script> 
</head>
<body>  
     <div id="map-canvas"></div>
</body> 
</html>

0 个答案:

没有答案