Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8597351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:53:39+00:00 2026-06-12T00:53:39+00:00

My code : directionsService.route(request, function (response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response);

  • 0

My code :

directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);

        map.setZoom(2);
    }
});

but the setZoom(2) won’t works. Seems that .setDirections is asynch.
Can’t set zoom after tracing the route?

Tried also with :

google.maps.event.addListener(directionsDisplay, 'directions_changed', function () {
    map.setZoom(2);
});

but the map won’t zoom…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:53:40+00:00Added an answer on June 12, 2026 at 12:53 am

    The DirectionsService does not change the zoom, the DirectionsDisplay (AKA DirectionsRenderer) does.

    The DirectionsRenderer has an option preserveViewport, which if included and set to true, will prevent it from changing the zoom (and center) of the map.

    If you want to set the the center based on the results of the directionsService, see my answer to this similar question:

    google map zoom after directions

    If you want the center the DirectionsRenderer would have set, use the bounds of the DirectionsResult.

    You can also listen for the directions_changed event, and set the zoom when it fires, not sure if that will work or not.

    example from the documentation using the zoom_changed event

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the code below to get the route between two points: directionsService.route(request, function(response,
The GDirections class of Google maps API helped me in displaying the route between
I wrote a piece of code with Google Map to realize the location and
I'm making a google maps project and need to create a route clicking on
All, When I use the Directions-service from Google Maps, it seems like the map
according to google maps i can plan a route that crosses over several waypoints.
I have strange problem with the Google Maps DirectionsService. It returns me different routes
Code : $('#myLink').click(function (e) { e.preventDefault(); ... if (someCondition) { ... code ... }
I trace a route through GMaps V3 and the DirectionsService . This is the
For the simplicity sake I have put the code for displaying the map and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.