/// <summary> /// Returns the heading from one LatLng to another LatLng. Headings are /// expressed in degrees clockwise from North within the range[-180, 180). /// </summary> /// <returns>The heading in degrees clockwise from north.</returns> public static double computeHeading(Position from, Position to) { // http://williams.best.vwh.net/avform.htm#Crs double fromLat = from.latitude.ToRadian(); double fromLng = from.longitude.ToRadian(); double toLat = to.latitude.ToRadian(); double toLng = to.longitude.ToRadian(); double dLng = toLng - fromLng; double heading = Math.Atan2( Math.Sin(dLng) * Math.Cos(toLat), Math.Cos(fromLat) * Math.Sin(toLat) - Math.Sin(fromLat) * Math.Cos(toLat) * Math.Cos(dLng)); return(GmsMathUtils.Wrap(heading.ToDegrees(), -180, 180)); }
/// <summary> /// Returns distance on the unit sphere; the arguments are in radians. /// </summary> private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) { return(GmsMathUtils.ArcHav(GmsMathUtils.HavDistance(lat1, lat2, lng1 - lng2))); }