1

我正在制作一张地图,其中我有 KML 负载,并且标记加载在同一个画布上,即使 kml 在画布上,我也希望边界在其中的标记很大。我将它与 php 结合使用,因此代码中有一些 php,但除了输入变量信息外,没有什么特别之处。

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">  
  jQuery(document).ready(function($) {
      if ($('#map_canvas').length != 0) {
                    var myLatlng = new google.maps.LatLng(45.266438, -93.233225);
                    var myOptions = {
                      zoom: 4,
                      center: myLatlng,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                    }
                    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                    var bounds = new google.maps.LatLngBounds();

                    var kmlLayer = new google.maps.KmlLayer('<?php bloginfo('template_url'); ?>/includes/delivery-maps/mansettisdel.kml', { map: map });

                var jsongeo = <?php echo(json_encode($geo_json)); ?>;               
                $.each(jsongeo, function(index, value) {  
                        var latlng = new google.maps.LatLng(value.lat,value.lng);
                        var marker = new google.maps.Marker({
                            position: latlng, 
                            map: map,
                            title:"Hello World!"
                            }); 
                        bounds.extend(latlng);
                    map.fitBounds(bounds);  

                    });                 

                    }    

    });
</script>

这是我通过纬度和经度循环的 json 的 var_dump。

string(617) "[{"type":"delivery","lat":"45.341969","lng":"-93.277657","date":"2011-07-11"},{"type":"delivery","lat":"45.005360","lng":"-93.323738","date":"2011-07-12"},{"type":"delivery","lat":"45.319408","lng":"-93.202446","date":"2011-07-12"},{"type":"delivery","lat":"45.131786","lng":"-93.216576","date":"2011-07-13"},{"type":"delivery","lat":"44.804131","lng":"-93.166885","date":"2011-07-13"},{"type":"delivery","lat":"45.119965","lng":"-93.287727","date":"2011-07-13"},{"type":"delivery","lat":"42.358433","lng":"-71.059776","date":"2011-07-13"},{"type":"delivery","lat":"34.195915","lng":"-84.507317","date":"2011-07-13"}]"

现在我没有遇到标记通过的问题,而只是边界问题。我不知道是否还有其他与 lat,long 相关的事情,但我读了很多,但找不到任何东西。

这是正在显示的内容。
出现了什么

这是我想展示的。 我想展示的

即使 KML 在地图上,我也希望标记成为界限。谷歌地图是否有将其设置为 KML 的内容,还是我的边界设置不正确?我注意到它转到边界视图,然后转到 KML 视图。

4

1 回答 1

1

尝试将选项 preserveViewport: true 添加到 KML 选项,使其显示为:

var kmlLayer = new google.maps.KmlLayer('<?php bloginfo('template_url'); ?>/includes/delivery-maps/mansettisdel.kml', { 
  map: map,
  preserveViewport: true
});

这应该会阻止它将其放大到 KML 范围内。

http://code.google.com/apis/maps/documentation/javascript/reference.html#KmlLayerOptions

于 2011-11-10T17:25:27.367 回答