Expand|Select|Wrap|Line Numbers
- endpoint.lat = 44.9631;
- endpoint.lng = -93.2492;
- //bus location from the southeast - the circle center
- startpoint.lat = 44.95517;
- startpoint.lng = -93.2427;
- function vehicleBearing(endpoint, startpoint) {
- endpoint.lat = x1;
- endpoint.lng = y1;
- startpoint.lat = x2;
- startpoint.lng = y2;
- var radians = getAtan2((y1 - y2), (x1 - x2));
- function getAtan2(y, x) {
- return Math.atan2(y, x);
- };
- var compassReading = radians * (180 / Math.PI);
- var coordNames = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"];
- var coordIndex = Math.round(compassReading / 45);
- if (coordIndex < 0) {
- coordIndex = coordIndex + 8
- };
- return coordNames[coordIndex]; // returns the coordinate value
- }