public IHttpActionResult PostGPSLocation(GPSLocation gPSLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.GPSLocation.Add(gPSLocation); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = gPSLocation.Id }, gPSLocation)); }
public void Test_GetLongitude() { // Arrange double expected = -4.1; GPSLocation GPSL = new GPSLocation(57.3, -4.1); // Act double actual = GPSL.getLongitude(); // Assert Assert.AreEqual(expected, actual); }
private void Awake() { if (m_Instance != null) { Destroy(gameObject); return; } m_Instance = this; DontDestroyOnLoad(gameObject); StartLocationTracking(); }
Vector3 CalculateFunPosition(GPSLocation location) { float x, y, z, normFactor; x = heritageBase.WarsawHeritage[heritageBase.activeOne].position.y - location.lon; z = heritageBase.WarsawHeritage[heritageBase.activeOne].position.x - location.lat; normFactor = Mathf.Sqrt(x * x + z * z); x *= -location.distance / normFactor; z *= -location.distance / normFactor; y = 0f; return(new Vector3(x, y, z)); }
private static void ggaDecoder_OnPositionReceived(object sender, GPSLocation location) { Debug.Print("Location information received."); Debug.Print("Time of reading: " + location.ReadingTime); Debug.Print("Latitude: " + DecodeDMPostion(location.Latitude)); Debug.Print("Longitude: " + DecodeDMPostion(location.Longitude)); Debug.Print("Altitude: " + location.Altitude.ToString("f2")); Debug.Print("Number of satellites: " + location.NumberOfSatellites); Debug.Print("Fix quality: " + location.FixQuality); Debug.Print("HDOP: " + location.HorizontalDilutionOfPrecision.ToString("f2")); Debug.Print("*********************************************\n"); }
public void Test_SetLatitude() { // Arrange double expected = 66.6; GPSLocation GPSL = new GPSLocation(0, 10); // Act GPSL.setLatitude(66.6); double actual = GPSL.getLatitude(); // Assert Assert.AreEqual(expected, actual); }
public void Test_SetLongitude() { // Arrange double expected = -1.66; GPSLocation GPSL = new GPSLocation(52.4, 0); // Act GPSL.setLongitude(-1.66); double actual = GPSL.getLongitude(); // Assert Assert.AreEqual(expected, actual); }
public static GPSLocation XMLCoordinateStringToGPSLocation(string coordinateString) { string[] parts = coordinateString.Split(','); double longitude = double.Parse(parts[0]); double latitude = double.Parse(parts[1]); GPSLocation targetIntersectionLocation = new GPSLocation() { Latitude = latitude, Longitude = longitude, }; return(targetIntersectionLocation); }
public TeamPin(Team team, MapSectionPage mapSection) : base(team, mapSection, size) { this.team = team; //Providing a link to the team that this pin represents this.mapSection = mapSection; //Updating image to match training and status of team in addition to text Update(); //Creating a context menu for TeamPin objects MenuItem[] menuItems = new MenuItem[4]; //Menu items for status change menuItems[0] = new MenuItem(); menuItems[0].Uid = "MenuItem_TeamPin_Available"; menuItems[0].Header = ETD.Properties.Resources.MenuItem_TeamPin_Available; menuItems[1] = new MenuItem(); menuItems[1].Uid = "MenuItem_TeamPin_Moving"; menuItems[1].Header = ETD.Properties.Resources.MenuItem_TeamPin_Moving; menuItems[2] = new MenuItem(); menuItems[2].Uid = "MenuItem_TeamPin_Intervening"; menuItems[2].Header = ETD.Properties.Resources.MenuItem_TeamPin_Intervening; menuItems[3] = new MenuItem(); menuItems[3].Uid = "MenuItem_TeamPin_Unavailable"; menuItems[3].Header = ETD.Properties.Resources.MenuItem_TeamPin_Unavailable; //Adding the method to be called when a menu item is clicked and adding the menuitem to the TeamPin context menu ContextMenu contextMenu = new ContextMenu(); for (int i = 0; i < menuItems.Length; i++) { menuItems[i].Click += ChangeStatus_Click; contextMenu.Items.Add(menuItems[i]); } this.ContextMenu = contextMenu; //When the context menu is opened, check the appropriate status of the team this.ContextMenu.Opened += CheckCurrentStatus_Opened; //Register as an observer to the team instance that this pin represents team.RegisterInstanceObserver(this); //Register as an observer to the GPS locations so that it will be notified when the GPS locations are changed (team has moved) if (team.getGPSLocation() != null) //The team has been associated to GPS locations { gpsLocation = team.getGPSLocation(); //Getting a direct pointer for ease of access only gpsLocation.RegisterInstanceObserver(this); } }
private async void GetCurrentLocation() { Map.Pins.Add(pinNew); while (IsRunning) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 0.1; // sets position to the current location var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(0.01)); // moving the map to Map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromKilometers(0.05))); // updating and setting pins location pinNew.Position = new Position(position.Latitude, position.Longitude); try { // getting current time string currentTime = DateTime.Now.ToString(); // creating object that is posted to MongoDb var post = new GPSLocation { fld_CrewName = (Application.Current as App).crewName, fld_Date = currentTime, fld_Lattitude = position.Latitude, fld_Longitude = position.Longitude }; // converting the object to json var requestString = JsonConvert.SerializeObject(post); // making it content var content = new StringContent(requestString, Encoding.UTF8, "application/json"); // posting var response = await client.PostAsync(Emulator, content); // to see what could be wrong var result = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { Console.WriteLine("Gps info was send to DB"); Console.WriteLine("Succesfull RESULT" + result); } else { Console.WriteLine("Something went wrong"); Console.WriteLine("Failed RESULT: " + result); } } catch (Exception e) { Console.WriteLine("Error with sending to server: " + e.Message); } await Task.Delay(1000); } }
private double CalcDistance(GPSLocation loc1, GPSLocation loc2) { // Haversine formula for calculating distance between two lat/lon values double lat1 = DegToRad(loc1.Latitude); double lat2 = DegToRad(loc2.Latitude); double deltaLat = DegToRad(loc2.Latitude - loc1.Latitude); double deltaLon = DegToRad(loc2.Longitude - loc1.Longitude); double a = Math.Pow(Math.Sin(deltaLat / 2.0), 2.0) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(deltaLon / 2.0), 2.0); double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); // 3959 is radius of earth in miles return(3959.0 * c); }
private bool GPSReady = false; //Even if the location service is running, the GPS might not be reporting correctly yet void Start() { Instance = this; photonView = GetComponent <PhotonView>(); if (PCVersion) { recentDebugInformation.text = "GPS not started since this is a PC version."; } else { StartCoroutine(StartGPS()); } }
public IHttpActionResult DeleteGPSLocation(int id) { GPSLocation gPSLocation = db.GPSLocation.Find(id); if (gPSLocation == null) { return(NotFound()); } db.GPSLocation.Remove(gPSLocation); db.SaveChanges(); return(Ok(gPSLocation)); }
public async Task <GetDirectionsResponse> GetPedestrianDirections(GPSLocation startLocation, GPSLocation endLocation) { GetDirectionsResponse getDirectionsResponse = null; var response = Enumerable.Empty <string>(); var requestUrl = GetDirectionsUrl(subscriptionKey, startLocation, endLocation); var(responseCode, responseBodySerialized) = await HttpClientHelper.GetAsync(requestUrl); if (responseCode == System.Net.HttpStatusCode.OK) { getDirectionsResponse = JsonConvert.DeserializeObject <GetDirectionsResponse>(responseBodySerialized); } return(getDirectionsResponse); }
public static double?HeadingBetweenTwoGPSLocations(GPSLocation fromLocation, GPSLocation toLocation) { var previousVehicleLocation = fromLocation; var currentVehicleLocation = toLocation; var lat1 = previousVehicleLocation.Latitude; var lon1 = previousVehicleLocation.Longitude; var lat2 = currentVehicleLocation.Latitude; var lon2 = currentVehicleLocation.Longitude; var bearing = DegreeBearing(lat1, lon1, lat2, lon2); return(bearing); }
public static double Calculate(GPSLocation location1, GPSLocation location2) { double loc1Lat = DegreesToRadians.ConvertToRadians(location1.Latitude); double loc1Long = DegreesToRadians.ConvertToRadians(location1.Longitude); double loc2Lat = DegreesToRadians.ConvertToRadians(location2.Latitude); double loc2Long = DegreesToRadians.ConvertToRadians(location2.Longitude); double deltaLong = Math.Abs(loc2Long - loc1Long); double delta = Math.Acos(Math.Sin(loc1Lat) * Math.Sin(loc2Lat) + Math.Cos(loc1Lat) * Math.Cos(loc2Lat) * Math.Cos(deltaLong)); return(Math.Round(earthRadiusInKms * delta, 2)); }
public override bool Equals(System.Object obj) { if (obj == null) { return(false); } if (obj is GPSLocation) { GPSLocation other = (GPSLocation)obj; return(this.latitude == other.latitude && this.longitude == other.longitude); } return(false); }
public static GLOSAResult ProjectedLaneForManeuver(MapData map, List <GPSLocation> gpsHistory, double?deviceHeading, ulong maneuver) { List <TrafficNode> trafficNodePositions = ExtractTrafficNodesFromMAP(map, maneuver); List <GPSLocation> gpsLocations = gpsHistory; GPSLocation location = gpsLocations.First(); var sortedList = trafficNodePositions. OrderBy(m => Distance.CalculateDistanceBetween2PointsKMs( m.GPSLocation.Latitude, m.GPSLocation.Longitude, location.Latitude, location.Longitude)).ToList(); TrafficNode nearestNode = sortedList[0]; MapDataIntersectionsIntersectionGeometryGenericLane lane = null; MapDataIntersectionsIntersectionGeometryGenericLane[] lanes = map.intersections.IntersectionGeometry.laneSet; var possibleLanes = lanes.Where(genricLane => genricLane.laneID.ToString() == nearestNode.ID); if (possibleLanes.Count() > 0) { lane = possibleLanes.First(); } // Verify the lane is in the same direction as the vehicle var nodes = ExtractTrafficNodesFromLane(lane); // Let's sort all lane nodes from MAP Ref Point var refPoint = map.intersections.IntersectionGeometry.refPoint; var mapLocation = new GPSLocation() { Latitude = refPoint.lat / Constants.MAPCoordinateIntConverterUnit, Longitude = refPoint.@long / Constants.MAPCoordinateIntConverterUnit, }; // Sort the nodes by distance ascending var sortedNodes = nodes.OrderBy(node => Distance.CalculateDistanceBetween2PointsKMs(node.GPSLocation.Latitude, node.GPSLocation.Longitude, mapLocation.Latitude, mapLocation.Longitude)).ToList(); GLOSAResult result = IsDirectionOfVehicleInSameDirectionAsLane(map.intersections.IntersectionGeometry.id.id, sortedNodes, deviceHeading, gpsHistory, 50, maneuver); result.Description = $"LaneId: {lane.laneID}, {result.Description}"; result.Object = lane; return(result); }
/// <summary> /// Process the data from a GLL message. /// </summary> /// <param name="data">String array of the message components for a GLL message.</param> public override void Process(string[] data) { if (OnGeographicLatitudeLongitudeReceived != null) { // // Status is stored in element 7 (position 6), A = valid, V = not valid. // if (data[6] == "A") { var location = new GPSLocation(); location.Latitude = NMEAHelpers.DegreesMinutesDecode(data[1], data[2]); location.Longitude = NMEAHelpers.DegreesMinutesDecode(data[3], data[4]); location.ReadingTime = NMEAHelpers.TimeOfReading(null, data[5]); OnGeographicLatitudeLongitudeReceived(this, location); } } }
public float calculateDistanceToLocationInM(GPSLocation otherLocation) { /* * The Haversine formula according to Dr. Math. * http://mathforum.org/library/drmath/view/51879.html * * dlon = lon2 - lon1 * dlat = lat2 - lat1 * a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 * c = 2 * atan2(sqrt(a), sqrt(1-a)) * d = R * c * * Where * dlon is the change in longitude * dlat is the change in latitude * c is the great circle distance in Radians. * R is the radius of a spherical Earth. * The locations of the two points in * spherical coordinates (longitude and * latitude) are lon1,lat1 and lon2, lat2. */ double kEarthRadiusKms = 6376.5; double dLat1InRad = deg2rad(this.latitude); double dLong1InRad = deg2rad(this.longitude); double dLat2InRad = deg2rad(otherLocation.latitude); double dLong2InRad = deg2rad(otherLocation.longitude); double dLongitude = dLong2InRad - dLong1InRad; double dLatitude = dLat2InRad - dLat1InRad; // Intermediate result a. double a = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) + Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) * Math.Pow(Math.Sin(dLongitude / 2.0), 2.0); // Intermediate result c (great circle distance in Radians). double c = 2.0 * Math.Asin(Math.Sqrt(a)); // Distance. // const Double kEarthRadiusMiles = 3956.0; double dDistance = kEarthRadiusKms * c * 1000.0; // 1000 meters in kilometer return((float)dDistance); }
public float calculateBearingToLocation(GPSLocation otherLocation) { double lat1 = deg2rad(this.latitude); double lon1 = deg2rad(this.longitude); double lat2 = deg2rad(otherLocation.latitude); double lon2 = deg2rad(otherLocation.longitude); double dLon = lon1 - lon2; double y = Math.Sin(dLon) * Math.Cos(lat2); double x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon); double brng = Math.Atan2(y, x); double bearingDegrees = (-rad2deg(brng) + 360.0) % 360.0; return((float)bearingDegrees); }
// coords is a string in form of: lat + "|" + long private void NewImage(string coords) { ResetGame(); var temp = coords.Split('|'); var gps = new GPSLocation(); try { gps.Latitude = float.Parse(temp[0]); gps.Longitude = float.Parse(temp[1]); _earth.CorrectPin .PinToGpsLocation(gps); } catch (FormatException ex) { print(ex.ToString()); } }
public void DistanceTest() { var location1 = new GPSLocation(40.7, -15.5); var location2 = new GPSLocation(40.9, -15.0); var location3 = new GPSLocation(40.7, -16); var location4 = new GPSLocation(-10.9, -10.0); var d1 = GPSLocation.GetDistanceInMeter(location1, location2); var d2 = GPSLocation.GetDistanceInMeter(location2, location3); var d3 = GPSLocation.GetDistanceInMeter(location3, location4); var d4 = GPSLocation.GetDistanceInMeter(location4, location1); Assert.AreEqual(47600, d1, d1 * 0.0001); Assert.AreEqual(87060, d2, d2 * 0.0001); Assert.AreEqual(5771000, d3, d3 * 0.0001); Assert.AreEqual(5765000, d4, d4 * 0.0001); Assert.AreEqual(location1 - location2, location2 - location1, 0.001); Assert.AreEqual(location2 - location3, location3 - location2, 0.001); }
//Tag the point at which the team is private static void TagPoint_Click(object sender, RoutedEventArgs e) { MenuItem mi = (MenuItem)sender; ContextMenu cm = (ContextMenu)mi.Parent; TeamPin teamPin = (TeamPin)cm.PlacementTarget; GPSLocation.referencePoints.Add(new GPSLocation(teamPin.getTeam().getGPSLocation().getLattitude(), teamPin.getTeam().getGPSLocation().getLongitude(), teamPin.getX() * GPSLocation.xRatio, teamPin.getY() * GPSLocation.yRatio)); MessageBox.Show("Point tagged"); if (GPSLocation.referencePoints.Count == 2) { MessageBox.Show("Setup completed"); GPSLocation.setConfigured(true); //Change flag to signify that the setup is successfully done mapSection.Update(); //Readding all the pins to the map setupOngoing = false; gpsStatusCallbacks.SetupCompleted(); //Notifying caller } }
//Choosing which (if any) gps location to use for the intervention coordinates internal void SelectGPSLocation() { //Dissociate from last GPS coordinates if (gpsLocation != null) { gpsLocation.DeregisterInstanceObserver(this); gpsLocation = null; } //Find a team that has a GPS location and attach self to it foreach (TeamPin teamPin in getInterveningTeamsPin()) { if (teamPin.getTeam().getGPSLocation() != null && teamPin.getTeam().getStatus() == Statuses.intervening) { gpsLocation = teamPin.getTeam().getGPSLocation(); gpsLocation.RegisterInstanceObserver(this); } } }
public static float CalculateBearingRadians(GPSLocation startLocation, GPSLocation endLocation) { double lat1, lat2, lon1, lon2; lat1 = startLocation.latitude.ToRadians(); lon1 = startLocation.longitude.ToRadians(); lat2 = endLocation.latitude.ToRadians(); lon2 = endLocation.longitude.ToRadians(); double dLon = lon2 - lon1; double x = Math.Sin(dLon) * Math.Cos(lat2); double y = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon); float radiansBearing = (float)Math.Atan2(x, y); return(radiansBearing); }
public override void UpdateLocation(GPSLocation location) { count++; countText.text = "C: " + count.ToString(); if (!gotLocation) { lastLoc = location; gotLocation = true; } else { double dist = CalcDistance(lastLoc, location); AddDistToStats(dist); distance += dist; distanceText.text = "D: " + distance.ToString(); lastLoc = location; } }
public Customer Deserialize(string searializedCustomer) { dynamic obj = JsonConvert.DeserializeObject(searializedCustomer); GPSLocation location = new GPSLocation { Longitude = obj.longitude, Latitude = obj.latitude }; Customer customer = new Customer { UserId = obj.user_id, Name = obj.name, Location = location }; return(customer); }
private IEnumerator downloadCloseGlyphs(GPSLocation newLocation) { Debug.LogError(downloadedGlyphs.ContainsKey(newLocation)); if (!downloadedGlyphs.ContainsKey(newLocation)) { downloadedGlyphs.Add(newLocation, null); // reserve key while (LoggedInUser.GetLoggedInUser() == null) { Debug.LogWarning("GPS updated but no user logged in. Waiting to download."); yield return(new WaitForSeconds(1.0f)); } GPSLocation[] closeBounds = newLocation.calculateLatLongBoundingBox(GlyphUniverse.MAX_RENDER_DISTANCE); ServerCall call = new ServerCall(ServerInteract.INSTANCE.GetGlyphsInArea(closeBounds)); yield return(StartCoroutine(call.call())); if (call.ReturnException != null) { Debug.LogException(call.ReturnException); } else { List <Glyph> closeGlyphs = (List <Glyph>)call.ObjectResponse; if (closeGlyphs.Count == 0) { fireGlyphDownloadedListeners(null); } else { foreach (Glyph glyph in closeGlyphs) { fireGlyphDownloadedListeners(glyph); } downloadedGlyphs [newLocation] = closeGlyphs; } } } yield return("Done"); }
public void Verify_DistanceIsAccuratelyCalculatedBetweenTwoLocations() { double expectedDistance = 10.57; var location1 = new GPSLocation { Longitude = -6.257664, Latitude = 53.339428 }; var location2 = new GPSLocation { Longitude = -6.238335, Latitude = 53.2451022 }; double actualDistance = DistanceCalculator.Calculate(location1, location2); Assert.Equal(expectedDistance, actualDistance, 2); }
public void TestGPSLocation() { GPSLocation location = new GPSLocation(); Assert.IsTrue(location.Started); }
public TrailGPSLocation setField(int subItemSelected, string s) { float pos = float.NaN; int valid = 1; TrailGPSLocation result = this; if (subItemSelected <= 2) { //check valid numbers try { if (!float.TryParse(s, out pos)) { pos = float.NaN; } } catch { pos = float.NaN; } if (float.IsNaN(pos) || subItemSelected == 1 && 90 < Math.Abs(pos) || subItemSelected == 2 && 180 < Math.Abs(pos) ) { valid = 0; } } if (valid > 0) { switch (subItemSelected) { case 1: _gpsLocation = new GPSLocation(this.LatitudeDegrees, pos); break; case 2: _gpsLocation = new GPSLocation(pos, this.LongitudeDegrees); break; default: this.Name = s; break; } } return result; }