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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:10:39+00:00 2026-05-26T03:10:39+00:00

I want to be able to draw routes on a web-based Google Map. I

  • 0

I want to be able to draw routes on a web-based Google Map. I have spent quite a bit of time looking at the Google Maps API and I have written the following Javascript:

$(document).ready(function () {
            $(function() {
                loadScript();
            });
});

function initialize() {
    var myOptions = {
        zoom: 10,
        disableDefaultUI: true,
        center: new google.maps.LatLng(51.5001524, -0.1262362),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById('fullscreen'), myOptions);

    var ck = Math.floor(Math.random() * 1000);
    var ctaLayer = new google.maps.KmlLayer('http://xxx/storage/kml/test.kml');
    ctaLayer.setMap(map);

}

function loadScript() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
    document.body.appendChild(script);
}

My .kml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="blueLine">
      <LineStyle>
        <color>ffff0000</color>
        <width>4</width>
      </LineStyle>
    </Style>
    <Style id="pinkLine">
      <LineStyle>
        <color>ffff33ff</color>
        <width>4</width>
      </LineStyle>
    </Style>
    <Placemark>
      <name>LHR-BSS</name>
      <visibility>1</visibility>
      <styleUrl>#blueLine</styleUrl>
      <description><![CDATA[LHR-BSS]]></description>
      <LineString>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <coordinates>
          -0.4534243,51.4703429,0
          4.4895353,50.9035504,0
        </coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>

Yet despite this, I can’t get the second line to draw within Google Maps. When I load the KML within Google Earth, it loads no problem. What am I doing wrong?

  • 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-26T03:10:40+00:00Added an answer on May 26, 2026 at 3:10 am

    This was far easier than I ever expected. I didn’t need the KML or the KML layer (which was notorious for caching btw). I simply used:

    var p = new google.maps.Polyline({ 
       map: m.map, 
       path: [hkg, end], 
       strokeColor: color, 
       geodesic: m.geodesic 
    });
    

    Making sure that when setting up the map, geodesic is set to true:

    var maps = {
                mymap: { 
                    map: null, 
                    geodesic: true, 
                    overlay: { path: null} }
     };
    

    With the lat longs set as google lat longs:

    var hkg = new google.maps.LatLng(22.3088856, 113.9141464); /*hong kong*/
    

    This worked a treat 🙂

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

Sidebar

Related Questions

I want to draw a route in google map with desites A & B
I want to make user able to draw routes and areas on static images
Using Python I want to be able to draw text at different angles using
I'm using Emacs, with CLISP and Slime, and want to be able to draw
I want to draw a route between two locations on the map. Something like
I want to be able to draw on to the top of a TextBlock,
I want to draw UIButton in following shape : I have cut the image,
I'm working on a game engine, and I want to be able to draw
So I want to be able to draw onto this canvas I created, let
So, i have a set of points (x,y), and i want to be able

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.