谷歌地图V3 Javascript获得使用KML和标记的界限

时间:2011-07-13 23:36:02

标签: google-maps google-maps-markers kml bounds

我正在制作一张地图,其中我有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"}]"

现在我没有遇到标记问题,只有边界问题。我不知道是否还有其他我需要做的东西,很长但是我读了这一吨并且找不到东西。

这是出现的内容 What shows up

以下是我想要展示的内容。 What I want to show up

即使KML在地图上,我也希望标记成为边界。谷歌地图有没有把它设置为KML,或者我的界限是否错误?我注意到它进入了边界视图,然后右转到KML视图。

1 个答案:

答案 0 :(得分: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