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 7725995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:05:55+00:00 2026-06-01T05:05:55+00:00

i have a simple google map, showing the driving directions from NY to LA,

  • 0

i have a simple google map, showing the driving directions from NY to LA, but when it loads on a page i would like to have it zoom in on a part of the route, not zoomed out totally to show the entire route from NY to LA, changing the Zoom doesn’t seem to work?

jsFiddle: http://jsfiddle.net/xtian/YNcsx/

JS:

    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;

    var neighborhoods = [];
    var VenueNames = [];
    var ShoutOut = [];
    var markers = [];
    var pics = [];
    var timeStamp = [];
    var iterator = 0; 

    var contentString;    

    var polylineOptionsActual = new google.maps.Polyline({
    strokeColor: '#ff3434',
    strokeOpacity: 0.8,
    strokeWeight: 5
    });    

function initialize() {
          var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
          directionsDisplay = new google.maps.DirectionsRenderer({polylineOptions: polylineOptionsActual});
          var myOptions = {
            zoom:5,
            strokeColor: "#000000",
            mapTypeId: google.maps.MapTypeId.ROADMAP
          }

          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          directionsDisplay.setMap(map);

          var start = "new york, ny";
          var end = "los angeles, ca";
          var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
          };
          directionsService.route(request, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(result);
            }
          });
      }    
$(document).ready(function() {
    initialize();
});​

HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <link rel="stylesheet" type="text/css" media="all" href="css/style.css" />
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCrCbLj7KnxfLpQjh2GF5hMwZqwAzS23Tw&sensor=false"></script>    
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/map-small.js"></script>
  </head>
  <body>
      <div class="container-front">
          <div class="map-container">
            <div id="map_canvas" style="width: 430px; height: 360px; border: 6px solid #024d91;"></div>
        </div>
    </div>
  </body>
</html>​
  • 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-01T05:05:57+00:00Added an answer on June 1, 2026 at 5:05 am

    You may create a LatLngBounds from start_location and end_location of the leg/step and use it as argument for map.fitBounds()

    map.fitBounds(new google.maps.LatLngBounds(result.routes[0].legs[0].steps[0].start_location)
                                         .extend(result.routes[0].legs[0].steps[0].end_location))
    

    also set the preserveViewport-option of directionsDisplay to true.

    http://jsfiddle.net/doktormolle/BRQff/

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

Sidebar

Related Questions

This seems simple but I've exhausted my Google search patience. I have a RelativeLayout
I have a custom google map. It seems very simple. <!DOCTYPE html PUBLIC -//W3C//DTD
I have a GWT web-app with a nearly full page Google map window. Inside
I have this simple hello world version of a google map api javascript v3
I have a Google Map with some simple buttons added to pan to different
I have created a simple app which shows a Google Map. I am testing
I have a Google map that is showing a number of markers. When the
I have implemented Simple Google Map Direction Api Javascript in my webpage. When my
I have a google map inside my android application which have a simple hardcoded
I have a page with a Google map and a slider made by me

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.