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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:10:53+00:00 2026-06-02T05:10:53+00:00

I am trying to use google maps API V3 to draw a line from

  • 0

I am trying to use google maps API V3 to draw a line from a default starting point and into a given direction given the distance. So for instance lets say my default starting point was San Francisco and the user inputs a distance, I want to be able to draw a straight line going eastward across the US based on that input distance. I came across this thing called bearing but im not sure how to use it correctly. Here is the code that I am working with:

function initializeMap(){

var mapOptions = {
center: new google.maps.LatLng(36.033036, -93.8655744),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};   

var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

var R = 6378137;
var dis = parseInt(document.form['input']['val'].value);
var bearing = 80; 
var lat2 = Math.asin(   Math.sin(37.470625)*Math.cos(dis/R)+Math.cos(37.470625)*Math.sin(dis/R)*Math.cos(bearing) );
var lon2 = -122.266823 + Math.atan2(Math.sin(bearing)*Math.sin(dis/R)*Math.cos(37.470625),Math.cos(dis/R)-Math.sin(37.470625)*Math.sin(-122.266823));


var impactP = new google.maps.Polyline({
  path: new google.maps.LatLng(lat2,lon2), 
              strokeColor: "#FF0000",
  strokeOpacity: 1.0,
          strokeWeight: 2
        });
impactP.setMap(map);
}

Can someone help me out please. I really want to get this to work.

  • 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-02T05:10:55+00:00Added an answer on June 2, 2026 at 5:10 am

    I put in the Google Maps scaffolding http://jsfiddle.net/khwLd/ but my math is off 🙁 You can see the lines veer off to the south. Googling “find terminal coordinates given a bearing and a distance” gave me a python function which I converted and checked but is still not giving the expected result.

    Calculating coordinates given a bearing and a distance

    What you need to do is fix all the math at the beginning so that:

    getDestination(origin_lat, origin_lng, bearing, distance) returns google.maps.LatLng(destination_lat, destination_lng)

    Sorry I wasn’t able to produce a full working solution 🙁

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

Sidebar

Related Questions

I'm trying to use the Google maps JavaScript API to draw a line between
I'm trying to use the google maps API to fetch direction times. I'm hoping
I'm trying to use Google Maps API and i'm stuck here: I need an
GOOGLE MAPS API V3 is what i'm trying to use. I have all the
I am trying to use the Google Maps API to get the latitude and
I was trying to use the google maps API within some jQuery ajax, however
I'm trying to use the Google maps geocode API to return all parks for
I'm trying to use the Google Maps V3 API to create markers on a
Am trying to use google.loader.ClientLocation along with the maps api to get the location
I'm experiencing a problem while trying to use google maps api v3 (with marker

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.