public static double Bearing(double lat1, double long1, double lat2, double long2) { lat1 = Geodesy.DegToRad(lat1); long1 = Geodesy.DegToRad(long1); lat2 = Geodesy.DegToRad(lat2); long2 = Geodesy.DegToRad(long2); double num = long2 - long1; return(Geodesy.ConvertToBearing(Geodesy.RadToDeg(Math.Atan2(Math.Sin(num) * Math.Cos(lat2), Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(num))))); }
public static void UpdatePosition(int idx) { try { int count = pts2.Count; if (count > 0 && idx <= count - 1) { string[] strArrays = Pos[idx].Split(new char[] { ';' }); if (!strArrays[0].ToUpper().StartsWith("N")) { strArrays[0] = string.Concat("-", strArrays[0].Substring(1)); } else { strArrays[0] = strArrays[0].Substring(1); } if (!strArrays[1].ToUpper().StartsWith("W")) { strArrays[1] = strArrays[1].Substring(1); } else { strArrays[1] = string.Concat("-", strArrays[1].Substring(1)); } if (idx > 2) { string[] strArrays1 = Pos[idx - 1].Split(new char[] { ';' }); if (!strArrays1[0].ToUpper().StartsWith("N")) { strArrays1[0] = string.Concat("-", strArrays1[0].Substring(1)); } else { strArrays1[0] = strArrays1[0].Substring(1); } if (!strArrays1[1].ToUpper().StartsWith("W")) { strArrays1[1] = strArrays1[1].Substring(1); } else { strArrays1[1] = string.Concat("-", strArrays1[1].Substring(1)); } LastLat = Convert.ToDouble(strArrays1[0]); LastLng = Convert.ToDouble(strArrays1[1]); if (LastLat != 0 && LastLng != 0) { double num = CalcDist(new PointLatLng(LastLat, LastLng), new PointLatLng(Convert.ToDouble(strArrays[0]), Convert.ToDouble(strArrays[1]))); double num1 = num * 5280 * 0.681818 * 0.621371; CompassBearing = (int)Geodesy.Bearing(LastLat, LastLng, Convert.ToDouble(strArrays[0]), Convert.ToDouble(strArrays[1])); compass.SetData((int)num1, CompassBearing); } } PointLatLng pointLatLng = new PointLatLng(Convert.ToDouble(strArrays[0]), Convert.ToDouble(strArrays[1])); mainMap.Overlays.Clear(); Markers.Markers.Clear(); GMapMarker gMapMarkerGoogleGreen = new GMapMarkerGoogleGreen(mainMap.Position); Markers.Markers.Add(gMapMarkerGoogleGreen); mainMap.Overlays.Add(Markers); mainMap.Position = pointLatLng; } } catch (Exception exception) { } }