JavaScript /谷歌地图 - map.fitBounds不起作用

时间:2017-06-01 00:42:48

标签: javascript google-maps

我试图在Google地图上绘制路线后适应地图的边界,由于某种原因,下面的内容没有得到应用,似乎它被忽略了,我甚至试图设置手动缩放,它也被忽略了:

       var bounds = response.routes[0].bounds;
       this.map.fitBounds(bounds);

以下是当前结果:enter image description here

function calculateAndDisplayRoute(directionsService, directionsDisplay) {
  directionsService.route({
    origin: pickUp.formattedAddress,
    destination: dropOff.formattedAddress,
    travelMode: 'DRIVING'
  }, function(response, status) {
    if (status === 'OK') {

       var bounds = response.routes[0].bounds;
       this.map.fitBounds(bounds);

    } else {
      console.log('Directions request failed due to ' + status);
    }
  });
}

0 个答案:

没有答案