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.