After extensive research and fun learning about Google's mapping api, I am building a digital antenna map application. At this point, the next step in the project plan is to build a memory-map replication of the google map that is locating digital tv stations based upon input from the user's address. So, I am using this math code to formulate the bearing of the center of the google map and a lat/lng point from the database result set.
My question is: How can I complete the math to show the bearing in degrees?
this code is the math that returns the following array result set:
1.21
1.10
1.10
1.10
1.10
2.62
-0.29
-1.17
0.12
3.04
var y = Math.sin(longitude-center.lng()) * Math.cos(latitude);
var x = Math.cos(center.lat())*Math.sin(latitude) - Math.sin(center.lat())*Math.cos(latitude)*Math.cos(longitude-center.lng());
var bearing = (Math.atan2(y, x)).toFixed(2);
There seems to something missing in my calculations. The db table is holding the longitude values as a negative number to represent the upper western quadrant of the globe.
Any suggestions to complete my math would save a million nuerons, I've already burned a trillion.
Taking the degrees to radian suggestion, I've modified the javascript code:
var radLat1 = center.lat() * Math.PI / 180;
var radLat2 = latitude * Math.PI / 180;
var radLng1 = center.lng() * Math.PI / 180;
var radLng2 = longitude * Math.PI / 180;
var y = Math.sin(radLng2- radLng1) * Math.cos(radLng2);
var x = Math.cos(radLat1)*Math.sin(radLat2) - Math.sin(radLat1)*Math.cos(radLat2)*Math.cos(radLng2-radLng1);
var bearing = (Math.atan2(y, x)).toFixed(2);
url to testing project site: click here
the div at the bottom of the page is a result set returned from 2 arrays, the first holding the distance and second holding the bearing measurement.