private double Mod(double a, double b) { return a - b * Math.Floor(a / b); } private void Button_Clicked(object sender, EventArgs e) { GetLocation(); // current_latitude = 25.2680572; // current_longitude = 55.3159565; // if (!OrientationSensor.IsMonitoring) OrientationSensor.Start(speed); double latt_from_radians = current_latitude * Math.PI / 180; double long_from_radians = current_longitude * Math.PI / 180; double latt_to_radians = HolyPlaceLatitude * Math.PI / 180; double lang_to_radians = HolyPlaceLongitude * Math.PI / 180; int the_r = 6371; // for miles // int r = 6371; // for kilometers // int r = 20, 903, 520; // to get the result in feet double law_of_cos_dist = Math.Acos((Math.Cos(latt_from_radians) * Math.Cos(latt_to_radians) * Math.Cos((-1 * lang_to_radians) - (-1 * long_from_radians))) + (Math.Sin(latt_from_radians) * Math.Sin(latt_to_radians))) * the_r; LabelA.Text = law_of_cos_dist.ToString(); double dLat = latt_to_radians - latt_from_radians; double dLong = lang_to_radians - long_from_radians; double the_a = Math.Pow((Math.Sin(dLat / 2)), 2) + Math.Cos(latt_from_radians) * Math.Cos(latt_to_radians) * Math.Pow((Math.Sin(dLong / 2)), 2); LabelB.Text = the_a.ToString(); double the_c = 2 * Math.Atan2(Math.Sqrt(the_a), Math.Sqrt(1 - the_a)); LabelC.Text = the_c.ToString(); double haversine_dist = the_c * the_r; double bearing = Math.Atan2(Math.Sin(lang_to_radians - long_from_radians) * Math.Cos(latt_to_radians), (Math.Cos(latt_from_radians) * Math.Sin(latt_to_radians)) - (Math.Sin(latt_from_radians) * Math.Cos(latt_to_radians) * Math.Cos(lang_to_radians - long_from_radians))); bearing = Mod(bearing, 2 * Math.PI); LabelD.Text = bearing.ToString(); double bearing_degree = bearing * 180 / Math.PI; LabelE.Text = bearing_degree.ToString(); pointer1.Value = bearing_degree; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)