Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping Math and Javascript
    primarykey
    data
    text
    <p>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. </p> <p>My question is: How can I complete the math to show the bearing in degrees?</p> <p>this code is the math that returns the following array result set:</p> <pre><code>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); </code></pre> <p>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.</p> <p>Any suggestions to complete my math would save a million nuerons, I've already burned a trillion.</p> <p>Taking the degrees to radian suggestion, I've modified the javascript code:</p> <pre><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); </code></pre> <p>url to testing project site: <a href="http://mapdemos.stewardtech.net" rel="nofollow noreferrer">click here</a></p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload