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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:36+00:00 2026-05-24T16:04:36+00:00

I have the following code which creates a map on a content page. <script

  • 0

I have the following code which creates a map on a content page.

<script type="text/javascript">
    var directionDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;

    function init() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var latlng = new google.maps.LatLng(54.6, -4.25);
        var startlatlng = new google.maps.LatLng(50.067, -5.717);
        var endlatlng = new google.maps.LatLng(58.633, -3.067);
        var myOptions = { zoom: 6, center: latlng, disableDefaultUI: true, mapTypeId: google.maps.MapTypeId.ROADMAP };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        directionsDisplay.setMap(map);
        calcRoute();
        var marker = new google.maps.Marker({ position: startlatlng, map: map, flat: true, title: "Start" });
        var marker = new google.maps.Marker({ position: endlatlng, map: map, flat: true, title: "Finish" });
        var marker = new google.maps.Marker({ position: new google.maps.LatLng(55.067, -4.717), map: map, flat: true, title: "Start" });
    }

    function calcRoute() {
        var startlatlng = new google.maps.LatLng(50.067, -5.717);
        var endlatlng = new google.maps.LatLng(58.633, -3.067);
        var request = {
            origin: startlatlng,
            destination: endlatlng,
            avoidHighways: true,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    }
    google.maps.event.addDomListener(window, 'load', init);
</script>

All I want is for the route to be displayed on the map created by function init but it is redrawing it at a lower zoom level, almost as if it is ignoring the first map. It is also overwriting my start and end markers. There seems to be very few parameters with directionService to control how the direction line is overlaid. Does anybody understand what is happening, because I don’t?

  • 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-05-24T16:04:38+00:00Added an answer on May 24, 2026 at 4:04 pm

    It seems the way to do this is to add the following at the start of function init():

    function init() {
        var rendererOptions = {
            preserveViewport: true
        };
        directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in javascript: <script type=text/javascript src=#{facesContext.externalContext.requestContextPath}/js/sample-points.js></script> <script type=text/javascript>//<![CDATA[ var cloudmade
I have the following script which creates an email from a contact form: http://codeviewer.org/view/code:1b54
I have the following JavaScript code: Link In which the function makewindows does not
I have the following code, which will not work. The javascript gives no errors
I have the following code which has been passed on to me and creates
I have the following code which creates a dynamic object that is assigned to
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which works just fine when the method is POST,
I have the following code which works fine. However, I only want to return

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.