void Update() { MoveQueuedEventsToExecuting(); while (_processingData.Count > 0) { var byteData = _processingData[0]; _processingData.RemoveAt(0); try { var gpsData = GPS_DataPacket.ParseDataPacket(byteData); TextTime.text = DateTime.Now.ToString("t"); TextLatitude.text = gpsData.Latitude.ToString(); TextLongitude.text = gpsData.Longitude.ToString(); if (Renderer != null) { var url = "http://maps.googleapis.com/maps/api/staticmap?center=" + gpsData.Latitude.ToString("F5") + "," + gpsData.Longitude.ToString("F5") + "&zoom=14&size=640x640&type=hybrid&sensor=true&markers=color:blue%7Clabel:S%7C" + gpsData.Latitude + "," + gpsData.Longitude; StartCoroutine(GetGoogleMap(new WWW(url), Renderer)); } } catch (Exception e) { TextLatitude.text = "Error: " + e.Message; } } }
public static GPS_DataPacket ParseDataPacket(byte[] data) { GPS_DataPacket gps_Data = new GPS_DataPacket(); gps_Data.Latitude = BitConverter.ToDouble(data, 0); gps_Data.Longitude = BitConverter.ToDouble(data, 8); gps_Data.Heading = BitConverter.ToSingle(data, 16); gps_Data.Speed = BitConverter.ToSingle(data, 20); return(gps_Data); }
void Update() { MoveQueuedEventsToExecuting(); while (_processingData.Count > 0) { var byteData = _processingData[0]; _processingData.RemoveAt(0); try { var gpsData = GPS_DataPacket.ParseDataPacket(byteData); TextTime.text = " Time: " + DateTime.Now.ToString("t"); TextLatitude.text = " Latitude: " + gpsData.Latitude.ToString(); TextLongitude.text = "Longitude: " + gpsData.Longitude.ToString(); TextLumens.text = " Lumens: " + gpsData.Lumens.ToString(); GpsHeading.text = " Heading: " + gpsData.Heading.ToString(); UserLat = gpsData.Latitude; // converts to float UserLong = gpsData.Longitude; // converts to float /* * if (Renderer != null) * { // Not used * var url = "http://maps.googleapis.com/maps/api/staticmap?center=" + gpsData.Latitude.ToString("F5") + "," + gpsData.Longitude.ToString("F5") + "&zoom=14&size=640x640&type=hybrid&sensor=true&markers=color:blue%7Clabel:S%7C" + gpsData.Latitude + "," + gpsData.Longitude; * StartCoroutine(GetGoogleMap(new WWW(url), Renderer)); * } */ } catch (Exception e) { TextLatitude.text = "Error: " + e.Message; } } // Compass tracked based on camera movement direct.z = playerTransform.eulerAngles.y; X_heading = (Math.Cos(UserLat) * Math.Sin(Math.Abs(UserLong - TargetLong))); Y_heading = ((Math.Cos(UserLat) * Math.Sin(TargetLat)) - (Math.Sin(UserLat) * Math.Cos(TargetLat) * Math.Cos(Math.Abs(UserLong - TargetLong)))); // Calculates direction to target var targetAngle = Math.Atan2(X_heading, Y_heading); var CompassAngle = -targetAngle * Mathf.Rad2Deg + direct.z; // Compass points toward target transform.localEulerAngles = new Vector3(0, 0, Convert.ToSingle(CompassAngle)); // Calculates and Displays distance to target //int targetDistant = Mathf.RoundToInt((Mathf.Sqrt(Mathf.Pow(xPosition, 2) + Mathf.Pow(yPosition, 2)))); TargetHeading.text = "Target: " + targetAngle.ToString(); }
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args) { ushort identifier = args.Advertisement.ManufacturerData.First().CompanyId; byte[] data = args.Advertisement.ManufacturerData.First().Data.ToArray(); var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var gpsData = GPS_DataPacket.ParseDataPacket(data); Debug.WriteLine(gpsData.ToString()); Time = DateTime.Now.ToString(); Latitude = gpsData.Latitude.ToString(); Longitude = gpsData.Longitude.ToString(); Bindings.Update(); /* GPS Data Parsing / UI integration goes here */ } ); }