public async Task <bool> GetCurrentPosition() { try { var geolocator = new Geolocator(); Geoposition position = await geolocator.GetGeopositionAsync(); var str = position.ToString(); Latitued = position.Coordinate.Latitude; Longitude = position.Coordinate.Longitude; await GetPlaceInfo(Latitued, Longitude); } catch { GetPlaceInfo(Latitued, Longitude); }; return(true); }
private async void SendDeviceToCloudMessagesAsync() { var accessStatus = await Geolocator.RequestAccessAsync(); double lat = 0; double lon = 0; switch (accessStatus) { case GeolocationAccessStatus.Allowed: // If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy.Default is used. Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = 0 }; // Carry out the operation. Geoposition pos = await geolocator.GetGeopositionAsync(); System.Diagnostics.Debug.WriteLine(pos); System.Diagnostics.Debug.WriteLine(pos.Coordinate.Latitude); System.Diagnostics.Debug.WriteLine(pos.Coordinate.Longitude); System.Diagnostics.Debug.WriteLine(pos.ToString()); lat = pos.Coordinate.Latitude; lon = pos.Coordinate.Longitude; break; case GeolocationAccessStatus.Denied: break; case GeolocationAccessStatus.Unspecified: break; } while (true) { try { // Check the value of the Sensor. // Temperature in Celsius is returned as a double type. Convert it to string so we can print it. sensor.Measure(); sensorTemp = sensor.TemperatureInCelsius; // Same for Humidity. sensorHum = sensor.Humidity; // Print all of the values to the debug window. System.Diagnostics.Debug.WriteLine("Temp is " + sensorTemp + " C. And the Humidity is " + sensorHum + "%. "); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("ERROR: " + ex); // NOTE: There are frequent exceptions of the following: // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '. // This appears to be caused by the rapid frequency of writes to the GPIO // These are being swallowed here/ // If you want to see the exceptions uncomment the following: // System.Diagnostics.Debug.WriteLine(ex.ToString()); } JsonValues telemetryDataPoint = new JsonValues { Id = DateTime.Now.ToString("yyyy-dd-M:hh:mm:ss"), name = "Pi1", humidity = sensorHum, temperature = sensorTemp, date = DateTime.Now.ToString("dd.MM.yyyy"), longitude = lon, latitude = lat }; System.Diagnostics.Debug.WriteLine(telemetryDataPoint); var messageString = JsonConvert.SerializeObject(telemetryDataPoint); var message = new Message(Encoding.ASCII.GetBytes(messageString)); //await deviceClient.SendEventAsync(message); //UploadToAzureStorage(messageString); await SendAsync(telemetryDataPoint); Task.Delay(10000).Wait(); } }