Hi, I am getting lat and long co-ordinates from Google using their places API. I want to be able to get the bearing between two points.
The below javascript code works but I'm not sure how to port it to VBA:
Thanks,
Tom
The below javascript code works but I'm not sure how to port it to VBA:
Code:
/**
* Calculate the bearing between two positions as a value from 0-360
* @param lat1 - The latitude of the first position
* @param lng1 - The longitude of the first position
* @param lat2 - The latitude of the second position
* @param lng2 - The longitude of the second position
*
* @return int - The bearing between 0 and 360
*/
//http://stackoverflow.com/questions/11415106/issue-with-calcuating-compass-bearing-between-two-gps-coordinates
function bearing (lat1,lng1,lat2,lng2) {
var dLon = (lng2-lng1);
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = this.toDeg(Math.atan2(y, x));
return Math.round(360 - ((brng + 360) % 360));
}
// Converts numeric degrees to radians
/**
* Since not all browsers implement this we have our own utility that will
* convert from degrees into radians
*
* @param deg - The degrees to be converted into radians
* @return radians
*/
function toRad(deg)
{
return deg * Math.PI / 180;
}
//convert from radians into degrees
/**
* Since not all browsers implement this we have our own utility that will
* convert from radians into degrees
* @param rad - The radians to be converted into degrees
* @return degrees
*/
function toDeg (rad) {
return rad * 180 / Math.PI;
}
Thanks,
Tom