Do not change map center or zoom level when rendering directions

前端 未结 2 845
花落未央
花落未央 2020-12-03 15:01

I want to have a large map of berlin from which you see multiple routes. Unfortunately a DirectionsRenderer zooms to the route so you have to manually zoom out again.

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 15:24

    In my case, this worked for me:

      let directionsService = new google.maps.DirectionsService();
            // always pass the `preserveViewport` to maintain the zoom ratio when using directionsRenderer
           let directionsRenderer = new google.maps.DirectionsRenderer({map:this.map,preserveViewport: true});
            //store the request state in an object ` use 'google.maps.TravelMode.DRIVING' instead of 'DRIVING'`
            var request = {
              origin: {query:start},
              destination: {query:end},
              travelMode: google.maps.TravelMode.DRIVING,
            };
            directionsService.route(request, function (response, status) {
             directionsRenderer.setDirections(response);
              // const route = request.routes;
           })
    

    i didn't have to pass the setMap method.

提交回复
热议问题