private void closeLogWriter() { if (null == _logWriter) { return; } Debug.Log("closing stream writer"); _logWriter.Dispose(); _logWriter = null; }
void LocationProvider_OnLocationUpdated(Location location) { /////////////// GUI logging ////////////////////// StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("IsLocationServiceEnabled: {0}", location.IsLocationServiceEnabled)); sb.AppendLine(string.Format("IsLocationServiceInitializing: {0}", location.IsLocationServiceInitializing)); sb.AppendLine(string.Format("IsLocationUpdated: {0}", location.IsLocationUpdated)); sb.AppendLine(string.Format("IsHeadingUpdated: {0}", location.IsUserHeadingUpdated)); string locationProviderClass = LocationProviderFactory.Instance.DefaultLocationProvider.GetType().Name; sb.AppendLine(string.Format("location provider: {0} ({1})", location.Provider, locationProviderClass)); sb.AppendLine(string.Format("UTC time:{0} - device: {1}{0} - location:{2}", Environment.NewLine, DateTime.UtcNow.ToString("yyyyMMdd HHmmss"), UnixTimestampUtils.From(location.Timestamp).ToString("yyyyMMdd HHmmss"))); sb.AppendLine(string.Format(_invariantCulture, "position: {0:0.00000000} / {1:0.00000000}", location.LatitudeLongitude.x, location.LatitudeLongitude.y)); sb.AppendLine(string.Format(_invariantCulture, "accuracy: {0:0.0}m", location.Accuracy)); sb.AppendLine(string.Format(_invariantCulture, "user heading: {0:0.0}°", location.UserHeading)); sb.AppendLine(string.Format(_invariantCulture, "device orientation: {0:0.0}°", location.DeviceOrientation)); sb.AppendLine(nullableAsStr <float>(location.SpeedKmPerHour, "speed: {0:0.0}km/h")); sb.AppendLine(nullableAsStr <bool>(location.HasGpsFix, "HasGpsFix: {0}")); sb.AppendLine(nullableAsStr <int>(location.SatellitesUsed, "SatellitesUsed:{0} ")); sb.AppendLine(nullableAsStr <int>(location.SatellitesInView, "SatellitesInView:{0}")); if (null != _logText) { _logText.text = sb.ToString(); } /////////////// file logging ////////////////////// // start logging to file if (_logToFile && null == _logWriter) { Debug.Log("--- about to start logging to file ---"); _logWriter = new LocationLogWriter(); _logToggle.GetComponentInChildren <Text>().text = "stop logging"; } // stop logging to file if (!_logToFile && null != _logWriter) { Debug.Log("--- about to stop logging to file ---"); _logToggle.GetComponentInChildren <Text>().text = "start logging"; closeLogWriter(); } // write line to log file if (_logToFile && null != _logWriter) { _logWriter.Write(location); } }