Maps API v3: Calculate bearing
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