Clean up and add location permissions in windows phone project
This commit is contained in:
parent
1d3cad9e67
commit
d75f48035f
@ -3,6 +3,8 @@ using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Services;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.Core.Models.Location;
|
||||
using eShopOnContainers.Core.Services.Location;
|
||||
using Plugin.Geolocator;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
@ -52,6 +54,13 @@ namespace eShopOnContainers
|
||||
{
|
||||
await GetRealLocation();
|
||||
}
|
||||
|
||||
if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId))
|
||||
{
|
||||
await SendCurrentLocation();
|
||||
}
|
||||
|
||||
base.OnResume();
|
||||
}
|
||||
|
||||
protected override void OnSleep()
|
||||
@ -59,14 +68,10 @@ namespace eShopOnContainers
|
||||
// Handle when your app sleeps
|
||||
}
|
||||
|
||||
protected override void OnResume()
|
||||
{
|
||||
// Handle when your app resumes
|
||||
}
|
||||
|
||||
private async Task GetRealLocation()
|
||||
{
|
||||
var locator = CrossGeolocator.Current;
|
||||
locator.AllowsBackgroundUpdates = true;
|
||||
locator.DesiredAccuracy = 50;
|
||||
|
||||
var position = await locator.GetPositionAsync(20000);
|
||||
@ -74,5 +79,18 @@ namespace eShopOnContainers
|
||||
Settings.Latitude = position.Latitude;
|
||||
Settings.Longitude = position.Longitude;
|
||||
}
|
||||
|
||||
private async Task SendCurrentLocation()
|
||||
{
|
||||
var location = new Location
|
||||
{
|
||||
Latitude = Settings.Latitude,
|
||||
Longitude = Settings.Longitude
|
||||
};
|
||||
|
||||
var locationService = ViewModelLocator.Resolve<ILocationService>();
|
||||
await locationService.UpdateUserLocation(location,
|
||||
Settings.AuthAccessToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,5 +25,6 @@
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
<Capability Name="privateNetworkClientServer" />
|
||||
<DeviceCapability Name="location" />
|
||||
</Capabilities>
|
||||
</Package>
|
Loading…
x
Reference in New Issue
Block a user