Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何创建缩放适合谷歌地图标记?_Javascript - Fatal编程技术网

Javascript 如何创建缩放适合谷歌地图标记?

Javascript 如何创建缩放适合谷歌地图标记?,javascript,Javascript,我在google map marker fit Zoom中遇到了一些问题。我正在以Xml格式动态获取latlng数据 这是我的代码。我需要一些帮助。请任何人帮助 var markers = xml.documentElement.getElementsByTagName('marker'); Array.prototype.forEach.call(markers, function(markerElem) { var id = markerElem.getA

我在google map marker fit Zoom中遇到了一些问题。我正在以Xml格式动态获取latlng数据

这是我的代码。我需要一些帮助。请任何人帮助

var markers = xml.documentElement.getElementsByTagName('marker');
        Array.prototype.forEach.call(markers, function(markerElem) {
          var id = markerElem.getAttribute('id');
          var name = markerElem.getAttribute('name');
          var address = markerElem.getAttribute('address');
          var type = markerElem.getAttribute('user_type');
          var point = new google.maps.LatLng(
              parseFloat(markerElem.getAttribute('lat')),
              parseFloat(markerElem.getAttribute('lng')));


            // var res = point.split({lat: lng:});

          var infowincontent = document.createElement('div');
          var strong = document.createElement('strong');
          strong.textContent = name
          infowincontent.appendChild(strong);
          infowincontent.appendChild(document.createElement('br'));

          var text = document.createElement('text');


          text.textContent = address//address view
          infowincontent.appendChild(text);
          var icon = customLabel[type] || {};
             var icons = ["http://maps.google.com/mapfiles/ms/icons/green.png","http://maps.google.com/mapfiles/ms/icons/blue.png",
                        "http://maps.google.com/mapfiles/ms/icons/yellow.png"
                         ];



            var marker = new google.maps.Marker({
            map: map,
            //icon:icons[i],
            icon:icons[Math.floor(Math.random()*icons .length)],
            position: point,
            label: icon.label
          });

您可以使用
fitBounds()
方法:

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

//extend the bounds for each marker that you add
bounds.extend(marker1.getPosition());
bounds.extend(marker2.getPosition());

//update the map to fit the bounds
map.fitBounds(bounds);

您可以使用
fitBounds()
方法:

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

//extend the bounds for each marker that you add
bounds.extend(marker1.getPosition());
bounds.extend(marker2.getPosition());

//update the map to fit the bounds
map.fitBounds(bounds);
看一看。也许这能帮到你!看一看。也许这能帮到你!