/// <summary> /// Updates data of each text box /// </summary>e void Update() { if (initialized) { foreach (KeyValuePair <Text, string> item in infoTextsDict) { item.Key.text = connection.GetValueByTopic(item.Value); } Vector3 dronePosition = this.gameObject.transform.localPosition; GPSCoordinate gps = WorldProperties.UnityCoordToGPSCoord(dronePosition); dronePosText.text = "Lat: " + String.Format("{0:0.0000000}", gps.Lat) + "\nLon: " + String.Format("{0:0.0000000}", gps.Lng); if (connection.HasAuthority()) { droneAuthorityText.text = "Controllable"; droneAuthorityText.color = Color.green; } else { droneAuthorityText.text = "Request Authority"; droneAuthorityText.color = Color.white; } // Make canvas always face the user as drone moves headsetTransform = VRTK_DeviceFinder.HeadsetTransform(); if (headsetTransform != null) { Vector3 targetPosition = headsetTransform.position; // canvas LookAt code is funky. Credit: https://answers.unity.com/questions/132592/lookat-in-opposite-direction.html menuCanvas.transform.LookAt(2 * menuCanvas.transform.position - targetPosition); } } }
//calcuate distance between the last two coordinates public static double CalcDistance(GPSCoordinate previous, GPSCoordinate current) { Location previousLoc = new Location(previous.Latitude, previous.Longitude); Location currentLoc = new Location(current.Latitude, current.Longitude); return(Location.CalculateDistance(previousLoc, currentLoc, DistanceUnits.Miles)); }
void RefreshCurrentLocation() { if (System.DateTime.Now > _lastRequest.AddSeconds(DEFAULT_TIMEOUT)) { _current = _provider.CurrentLocation; } }
void AddLocation_Click(object sender, EventArgs e) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { locationLinearlayout.Visibility = ViewStates.Visible; tvbLatitude.Text = "Lat: " + location.Latitude.ToString(); tvbLongitude.Text = "Long: " + location.Longitude.ToString(); accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); _GPSCoordinates = new GPSCoordinate() { Latitude = location.Latitude.ToString(), Longitude = location.Longitude.ToString() }; building.GPSCoordinates = _GPSCoordinates; } }
public GPSCoordinate GetExifGpsFromImage(Image image) { var latRef = image.PropertyItems.FirstOrDefault(p => p.Id == 1); var lat = image.PropertyItems.FirstOrDefault(p => p.Id == 2); var lonRef = image.PropertyItems.FirstOrDefault(p => p.Id == 3); var lon = image.PropertyItems.FirstOrDefault(p => p.Id == 4); var gpsUtc = image.PropertyItems.FirstOrDefault(p => p.Id == 7); var utc = image.PropertyItems.FirstOrDefault(p => p.Id == 306); if (lat == null && lon == null && gpsUtc == null) { return(new GPSCoordinate("No GPS information for this image.") { FileTime = GetDateTimeFromProperty(utc) }); } var gpsUtcParts = GetRationalNumbersFromValue(gpsUtc); GPSCoordinate gPSCoordinate = GetGPSCoordinateFromProperties(latRef, lat, lonRef, lon); gPSCoordinate.FileTime = GetDateTimeFromProperty(utc); gPSCoordinate.UtcTime = new DateTime(gPSCoordinate.FileTime.Year, gPSCoordinate.FileTime.Month, gPSCoordinate.FileTime.Day, (int)gpsUtcParts[0], (int)gpsUtcParts[1], (int)gpsUtcParts[2]); return(gPSCoordinate); }
public bool UpdateLocation(int timeout) { bool result = false; if (_manager != null) { DateTime lastTime = DateTime.Now; while (lastTime.AddSeconds(timeout) > DateTime.Now) { CLLocation location = _manager.Location; if (location != null) { DateTime time = DateTime.SpecifyKind(location.Timestamp, DateTimeKind.Unspecified); if (DateTime.UtcNow < time.AddMinutes(5)) { _currentLocation = new GPSCoordinate(location.Coordinate.Latitude, location.Coordinate.Longitude, time); result = true; break; } } } } return(result); }
private void DataGridRow_MouseUp(object sender, MouseButtonEventArgs e) { DataGridRow row = (DataGridRow)sender; GPSCoordinate gps = row.Item as GPSCoordinate; imgPreview.Source = new BitmapImage(new Uri(gps.FileName)); }
static GPSCoordinate Convert(Location location) { GPSCoordinate result = location != null ? new GPSCoordinate(location.Latitude, location.Longitude, location.Time.ToDateTime().ToLocalTime()) : new GPSCoordinate(); return(result); }
private GPSCoordinate GetGPSCoordinateFromProperties(PropertyItem latRef, PropertyItem lat, PropertyItem lonRef, PropertyItem lon) { GPSCoordinate result = new GPSCoordinate( GetGeoLineFromProperties(latRef, lat, GeoLineType.Latitude), GetGeoLineFromProperties(lonRef, lon, GeoLineType.Longitude)); return(result); }
public Quest(Quest_info info, int xp_reward, int level, GPSCoordinate Start_co, GPSCoordinate stop_co) { this.info = info; this.Xp_reward = xp_reward; this.Level = level; this.Start_co = Start_co; this.Stop_co = stop_co; crossedRadZone = false; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewModel = new FacilitiesViewModel(); Inflater = inflater; Container = container; view = inflater.Inflate(Resource.Layout.fragment_facility_information, container, false); editButton = view.FindViewById <FloatingActionButton>(Resource.Id.editfacilityinfo_button); saveButton = view.FindViewById <FloatingActionButton>(Resource.Id.savefacilityinfo_button); clientCode = view.FindViewById <TextView>(Resource.Id.tvf_clientcode); facilityName = view.FindViewById <TextView>(Resource.Id.tvf_facilityname); settlementtype = view.FindViewById <Spinner>(Resource.Id.sf_settlementtype); zoning = view.FindViewById <Spinner>(Resource.Id.sf_zoning); locationHolder = view.FindViewById <CardView>(Resource.Id.tvf_locationholder); responsiblepersonHolder = view.FindViewById <CardView>(Resource.Id.tvf_responsiblepersonholder); deedHolder = view.FindViewById <CardView>(Resource.Id.tvf_deedholder); pictureHolder = view.FindViewById <ImageView>(Resource.Id.facilityphotoimageinfo); facility = new Facility(); AppPreferences ap = new AppPreferences(Android.App.Application.Context); var data = Arguments.GetString("data"); if (data != null) { facility = Newtonsoft.Json.JsonConvert.DeserializeObject <Facility>(data); clientCode.Text = facility.ClientCode; facilityName.Text = facility.Name; settlementtype.SetSelection(GetIndex(settlementtype, facility.SettlementType)); zoning.SetSelection(GetIndex(zoning, facility.Zoning)); imageNames = facility.IDPicture == null ? new List <string>() : facility.IDPicture.Split(',').ToList(); if (imageNames.Count > 0) { GetImages(ap); } } pictureHolder.Click += (sender, e) => { var intent = new Intent(Activity, typeof(FacilityPictureActivity)); intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(facility)); StartActivity(intent); }; settlementtype.Enabled = false; zoning.Enabled = false; saveButton.Visibility = ViewStates.Gone; editButton.SetBackgroundColor(Android.Graphics.Color.Tan); saveButton.SetBackgroundColor(Android.Graphics.Color.Tan); editButton.Click += EditButton_Click; saveButton.Click += SaveButton_Click; locationHolder.Click += Location_Click; responsiblepersonHolder.Click += ResponsiblePerson_Click; deedHolder.Click += Deed_Click; _GPSCoordinates = new GPSCoordinate(); _BoundryPolygons = new List <BoundryPolygon>(); return(view); }
public ExtraFieldsFall(Fall CurrentFall) { InitializeComponent(); CurrentFallReportVM = new FallReportVM(); CurrentFallPredictionVM = new FallPredictionVM(); GPSCoordinate fallPredictionLocation = Prediction(CurrentFall).FallPredictionLocation; DataContext = this; RealLocation = CurrentFall.FallLocation.Latitude.ToString() + " " + "," + " " + CurrentFall.FallLocation.Longitude.ToString(); CalculatedLocation = fallPredictionLocation.Latitude.ToString() + " " + "," + " " + fallPredictionLocation.Longitude.ToString(); ReportsNumber = CalculateReportNumber(CurrentFall); }
private void CreateEditGPSCoordinates(GPSCoordinate GPSCoordinates, ref ApplicationUnit unit) { if (GPSCoordinates.Id != 0) { unit.GPSCoordinates.Update(GPSCoordinates); } else { unit.GPSCoordinates.Add(GPSCoordinates); } unit.SaveChanges(); }
private GPSCoordinate GPSCoordinates(GPSCoordinate gpsCoordinate, ref ApplicationUnit unit) { if (gpsCoordinate != null) { GPSCoordinate gps = unit.GPSCoordinates.GetAll() .FirstOrDefault(p => p.Id == gpsCoordinate.Id); if (gps != null) { return(gps); } } return(gpsCoordinate); }
//Calculate total distance public double CalculateDistance(params GPSCoordinate[] coordinates) { double totalDistance = 0.0; for (int i = 0; i < coordinates.Length - 1; i++) { GPSCoordinate current = coordinates[i]; GPSCoordinate next = coordinates[i + 1]; totalDistance += CalculateDistance(current, next); } return(totalDistance); }
private void G_IncludedInMapChanged(object sender, EventArgs e) { GPSCoordinate coordinate = sender as GPSCoordinate; if (!coordinate.IncludedInMap && selectAll.IsChecked.Value) { selectAll.IsChecked = false; } else if (CaseFile.GPSCoordinates.All(g => g.IncludedInMap) && !selectAll.IsChecked.Value) { selectAll.IsChecked = true; } PlotMapData(CaseFile.GPSCoordinates.Where(g => g.IncludedInMap).ToList()); }
public Quest Gen_Quest() { ArrayList AllCo = Make_quests.Gen_GPSCoordinates(); ArrayList Allinfo = Make_quests.Gen_quest_info(); int Xp = Gen_xp.Xp_gen(); int Level = Gen_level.Level_gen(); int coord = rand.Next(((11 - 0) + 1)); int info = rand.Next(((6 - 0) + 1)); Quest_info qi = (Quest_info)Allinfo[info]; GPSCoordinate gps = (GPSCoordinate)AllCo[coord]; Quest AQuest = new Quest(qi, Xp, Level, null, gps); return(AQuest); }
////////////////////////////////////////////////////////////////////////////////////////// //Distance in KM, using Haversine formula///////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// public double CalculateDistance(GPSCoordinate from, GPSCoordinate to) { var lat1Rad = DegreesToRadians(from.latitude.ToDouble()); var lat2Rad = DegreesToRadians(to.latitude.ToDouble()); var dlat1lat2 = DegreesToRadians((to.latitude.ToDouble() - from.latitude.ToDouble())); var dlong1long2 = DegreesToRadians((to.longitude.ToDouble() - from.longitude.ToDouble())); var a = Math.Sin(dlat1lat2 / 2) * Math.Sin(dlat1lat2 / 2) + Math.Cos(lat1Rad) * Math.Cos(lat2Rad) * Math.Sin(dlong1long2 / 2) * Math.Sin(dlong1long2 / 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); //Set to one decimal places return(Math.Round((EarthRadius * c) / 1000, DistancePrecision)); }
public void Update(Fall CurrentFall) { CurrentFallReportVM = new FallReportVM(); CurrentFallPredictionVM = new FallPredictionVM(); GPSCoordinate fallPredictionLocation = Prediction(CurrentFall).FallPredictionLocation; DataContext = this; if (RealLocation != null) { RealLocation = CurrentFall.FallLocation.Latitude.ToString() + " " + "," + " " + CurrentFall.FallLocation.Longitude.ToString(); } if (CalculatedLocation != "") { CalculatedLocation = fallPredictionLocation.Latitude.ToString() + " " + "," + " " + fallPredictionLocation.Longitude.ToString(); } ReportsNumber = CalculateReportNumber(CurrentFall); }
public static async Task <GPSCoordinate> GetCoordinatesAsync(double elapsedTime) { GPSCoordinate coordinate = new GPSCoordinate(); try { var request = new GeolocationRequest(GeolocationAccuracy.Best); var myLocation = await Geolocation.GetLocationAsync(request); //var location = await Task.Run( ()=> Geolocation.GetLastKnownLocationAsync()); if (myLocation != null) { Console.WriteLine($"Latitude: {myLocation.Latitude}, Longitude: {myLocation.Longitude}, Altitude: {myLocation.Altitude}"); coordinate.Latitude = myLocation.Latitude; coordinate.Longitude = myLocation.Longitude; coordinate.ElapsedTimeInSec = elapsedTime; } return(coordinate); } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception throw new NotImplementedException(); } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception throw new NotImplementedException(); } catch (PermissionException pEx) { // Handle permission exception throw new NotImplementedException(); } catch (Exception ex) { // Unable to get location coordinate.Latitude = 0; coordinate.Longitude = 0; coordinate.ElapsedTimeInSec = elapsedTime; coordinate.message = "Error - unable to get location"; return(coordinate); } }
public bool StartTracking() { if (_manager != null && !_trackingStarted) { _startTime = DateTime.UtcNow; _currentLocation = new GPSCoordinate(); _manager.StartUpdatingLocation(); if (new Version(UIDevice.CurrentDevice.SystemVersion).Major > 7) { _manager.RequestAlwaysAuthorization(); } _trackingStarted = true; return(true); } return(false); }
////////////////////////////////////////////////////////////////////////////////////////// //Mid Point calculation/////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// public GPSCoordinate CalculateMiddle(GPSCoordinate from, GPSCoordinate to) { double lat1Rad = DegreesToRadians(from.latitude.ToDouble()); double lat2Rad = DegreesToRadians(to.latitude.ToDouble()); double long1Rad = DegreesToRadians(from.longitude.ToDouble()); double long2Rad = DegreesToRadians(to.longitude.ToDouble()); double Bx = Math.Cos(lat2Rad) * Math.Cos(long2Rad - long1Rad); double By = Math.Cos(lat2Rad) * Math.Sin(long2Rad - long1Rad); double latM = Math.Atan2(Math.Sin(lat1Rad) + Math.Sin(lat2Rad), Math.Sqrt((Math.Cos(lat1Rad) + Bx) * (Math.Cos(lat1Rad) + Bx) + By * By)); double longM = long1Rad + Math.Atan2(By, Math.Cos(lat1Rad) + Bx); var a = RadiansToDegree(latM); var b = RadiansToDegree(longM); return(new GPSCoordinate(new GPSDegree(RadiansToDegree(latM)), new GPSDegree(RadiansToDegree(longM)))); }
public async Task GetLocationAsync() { if ((stopwatch.Elapsed.TotalSeconds / _nextGPSReading) >= 1.0) { GPSCoordinate coordinates = await GPSLocation.GetCoordinatesAsync(stopwatch.Elapsed.TotalSeconds); Locations.Add(coordinates); if (Locations.Count > 1) { DistanceInMiles += GPSLocation.CalcDistance(Locations[Locations.Count - 1], Locations[Locations.Count - 2]); if (DistanceInMiles > .3) { PaceActual = (stopwatch.Elapsed.TotalSeconds / 60) / DistanceInMiles; } } _nextGPSReading += _gpsIntervalInSec; } }
static void Main(string[] args) { Console.WriteLine("GPS Triangulator is running..."); GPSCoordinate gps1, gps2; gps1 = new GPSCoordinate(new GPSDegree(50, 3, 59), new GPSDegree(5, 42, 53)); gps2 = new GPSCoordinate(new GPSDegree(58, 38, 38), new GPSDegree(3, 04, 12)); double distance = GPSMath.GPSMathProcessor.Get().CalculateDistance(gps1, gps2); Console.WriteLine("Distance : " + distance.ToString()); var mid = GPSMath.GPSMathProcessor.Get().CalculateMiddle(gps1, gps2); Console.WriteLine("Mid : " + mid.ToString()); Console.ReadLine(); }
public GPSCoordinate GetGeoTaggingFromImage(string imagePath) { imagePath.Replace(@"\", "/"); ExifReader reader = null; try { reader = new ExifReader(imagePath); } catch (Exception) { reader = new ExifReader(@"C:\Users\litalush\Documents\ConsoleApp1 (2)\ConsoleApp1\PL\images\2.jpg"); } // EXIF lat/long tags stored as [Degree, Minute, Second] double[] latitudeComponents; double[] longitudeComponents; string latitudeRef; // "N" or "S" ("S" will be negative latitude) string longitudeRef; // "E" or "W" ("W" will be a negative longitude) if (reader.GetTagValue(ExifTags.GPSLatitude, out latitudeComponents) && reader.GetTagValue(ExifTags.GPSLongitude, out longitudeComponents) && reader.GetTagValue(ExifTags.GPSLatitudeRef, out latitudeRef) && reader.GetTagValue(ExifTags.GPSLongitudeRef, out longitudeRef)) { var temp = new GPSCoordinate(); var latitude = ConvertDegreeAngleToDouble(latitudeComponents[0], latitudeComponents[1], latitudeComponents[2], latitudeRef); var longitude = ConvertDegreeAngleToDouble(longitudeComponents[0], longitudeComponents[1], longitudeComponents[2], longitudeRef); temp.Latitude = latitude; temp.Longitude = longitude; return(temp); } return(null); }
public static ArrayList In_rad_zone(GPSCoordinate current) { for (int i = 0; (i < 10); i++) { //Generate 10 random radiation zones around the user's location double randomLatitudeOffset = (rand.NextDouble() * 0.1) - 0.05; double randomLongitudeOffset = (rand.NextDouble() * 0.1) - 0.05; double zoneLatitide = randomLatitudeOffset + current.Lat; double zoneLongitude = randomLongitudeOffset + current.Lon; double radius = (rand.NextDouble() * 350) + 50; GPSCoordinate gpsCoordinate = new GPSCoordinate(zoneLatitide, zoneLongitude, "Radiation Zone"); rads.Add(new Radiation_Zone(gpsCoordinate, radius)); } foreach (Radiation_Zone zone in rads) { Debug.Log("Coordinate: " + zone.coordinate.Lat + ", " + zone.coordinate.Lon + " Radius: " + zone.radius); } return(rads); }
private static IEnumerable <TableCell> GetTableCellsFromGpsCoordinate(GPSCoordinate gps) { Type gpsCoordType = typeof(GPSCoordinate); var props = gpsCoordType.GetProperties(); var result = new List <TableCell>(); foreach (var gpsProp in props) { var attribs = gpsProp.GetCustomAttributes(typeof(DisplayNameAttribute), false); if (attribs.Any()) { var tc = new TableCell(); var propVal = gpsProp.GetValue(gps); if (propVal != null) { tc.Append(new Paragraph(new Run(new Text(propVal.ToString())))); tc.Append(new TableCellProperties( new TableCellWidth { Type = TableWidthUnitValues.Auto })); result.Add(tc); } else { tc.Append(new Paragraph(new Run(new Text("")))); tc.Append(new TableCellProperties( new TableCellWidth { Type = TableWidthUnitValues.Auto })); result.Add(tc); } } } return(result); }
public static string ToDegreesMinutesSeconds(double decVal, GPSCoordinate coord) { var nfi = new NumberFormatInfo { NumberDecimalSeparator = "." }; var _ = string.Empty; var num1 = Math.Abs((int)decVal); var num = Math.Abs(num1); var single1 = (float)(60 * (Math.Abs(decVal) - (double)num1)); var single = Math.Abs(single1); if (coord == GPSCoordinate.Latitude) { if (decVal >= 0) { _ = num.ToString("00", nfi); return(string.Concat(_, single.ToString("00.0000", nfi), "N")); } _ = num.ToString("00", nfi); return(string.Concat(_, single.ToString("00.0000", nfi), "S")); } if (coord != GPSCoordinate.Longitude) { return(null); } if (decVal >= 0) { _ = num.ToString("000", nfi); return(string.Concat(_, single.ToString("00.0000,", nfi), "E")); } _ = num.ToString("000", nfi); return(string.Concat(_, single.ToString("00.0000", nfi), "W")); }
/// <summary> /// Maps the GPS coordinate using Google Maps /// </summary> /// <param name="g">The GPS Coordinate.</param> private void MapGpsCoordinate(GPSCoordinate g) { if (g != null) { // Create URL. string url = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + g.ToString(); // Open URL in default browser. System.Diagnostics.Process.Start(url); } else { MessageBox.Show("No GPS Coordinate present to Map."); } return; }
public static GPSCoordinate DecryptGPSCoordinate(GPSCoordinate gpscoord) { gpscoord.Latitude = StringCipher.Decrypt(gpscoord.Latitude, EncryptKey); gpscoord.Longitude = StringCipher.Decrypt(gpscoord.Longitude, EncryptKey); return(gpscoord); }
private double GetDinstance(GPSCoordinate gPSCoordinate1, GPSCoordinate gPSCoordinate2) { return((new GeoCoordinate(gPSCoordinate1.Latitude, gPSCoordinate1.Longitude)).GetDistanceTo(new GeoCoordinate(gPSCoordinate2.Latitude, gPSCoordinate2.Longitude))); }