After extensive research and fun learning the Google mapping api, I am building a digital antenna map application. At this stage, the next step in the project plan is to create a replication of the memory card on the google map, which houses digital television stations based on input from a user address. So, I use this math code to formulate a google map center support and a lat / lng point from a database result set.
My question is: how can I finish the math to show the bearing in degrees?
this code is math that returns the following array:
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);
Something is missing in my calculations. Table db holds the longitude values ββas a negative number to represent the upper western quadrant of the globe.
Any suggestions to finish the math would save a million nouons, I already burned a trillion.
Taking degrees to the radian sentence, I changed 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 for testing the project site: click here
The div at the bottom of the page is the result set returned from 2 arrays, the first of which holds the distance and the second holds the bearing dimension.
source share