Maps API v3: Calculate bearing
google-maps-api-3, javascript
Solution
You can use the Geometry Library.
You need to add it to the API call:
`https://maps.googleapis.com/maps/api/js?libraries=geometry`
Then use the `computeHeading` method:
var heading = google.maps.geometry.spherical.computeHeading(pointA, pointB);
where `pointA` and `pointB` are the two `LatLng` objects.
https://developers.google.com/maps/documentation/javascript/reference?csw=1#spherical
Problem
I've been struggling with this for a while & need some advice. I have seen some similar topics but can't find an answer that works for me. I am creating an app using google maps API that will determine your location, determine a specific point (point b) and then move an arrow to point in the direction of point b. I am having trouble calculating the bearing, could anyone offer some assistance? I have: - the lat/lng of point a - the lat/lng of point b - the device knows where North is and I am able to calculate how many degrees away from north the device is pointing I need: a calculation that will take this information and spit out a number of degrees to point the arrow. I have looked here which seems useful but I still can't get it working - it's returning NaN http://www.movable-type.co.uk/scripts/latlong.html I'm not really a js pro so would really appreciate some guidance here. Thanks very much!