private async Task <Model.Position> CurrentPosition() { Model.Position pObj = new Model.Position(); try { //basic //var location = await Geolocation.GetLastKnownLocationAsync(); var request = new GeolocationRequest(GeolocationAccuracy.High); var location = await Geolocation.GetLocationAsync(request); if (location != null) { pObj.Lat = location.Latitude; pObj.Log = location.Longitude; pObj.Alt = location.Altitude; pObj.GeoCodeAddress = await CurrentPositionPlace(location.Latitude, location.Longitude); } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception pObj.MessageError = fnsEx.Message; } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception pObj.MessageError = fneEx.Message; } catch (PermissionException pEx) { // Handle permission exception pObj.MessageError = pEx.Message; } catch (Exception ex) { // Unable to get location pObj.MessageError = ex.Message; } return(pObj); }
/// <summary> /// send to Api /// </summary> /// <returns></returns> async Task SendToApi(Model.Position position) { Console.WriteLine("=> Sending to api direct"); Console.WriteLine($"=> lat: {position.Lat}, log: {position.Log}, place: {position.GeoCodeAddress.AdminArea}"); }