Skip to content

Commit 41398ab

Browse files
David BritchDavid Britch
authored andcommitted
Work in progress.
1 parent 68d0783 commit 41398ab

26 files changed

Lines changed: 923 additions & 39 deletions

src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
using eShopOnContainers.Core.Services.Settings;
44
using eShopOnContainers.Core.ViewModels.Base;
55
using eShopOnContainers.Services;
6-
using Plugin.Geolocator;
76
using System.Globalization;
87
using System.Threading.Tasks;
98
using Xamarin.Forms;
109
using Xamarin.Forms.Xaml;
10+
using eShopOnContainers.Core.Services.Dependency;
1111

1212
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
1313
namespace eShopOnContainers
@@ -69,13 +69,16 @@ protected override void OnSleep()
6969

7070
private async Task GetGpsLocation()
7171
{
72-
var locator = CrossGeolocator.Current;
72+
var dependencyService = ViewModelLocator.Resolve<IDependencyService>();
73+
var locator = dependencyService.Get<ILocationServiceImplementation>();
7374

7475
if (locator.IsGeolocationEnabled && locator.IsGeolocationAvailable)
7576
{
76-
locator.AllowsBackgroundUpdates = true;
77+
//locationService.AllowsBackgroundUpdates = true;
7778
locator.DesiredAccuracy = 50;
7879

80+
await Task.Delay(5000);
81+
7982
var position = await locator.GetPositionAsync();
8083

8184
_settingsService.Latitude = position.Latitude.ToString();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace eShopOnContainers.Core.Models.Location
2+
{
3+
public enum ActivityType
4+
{
5+
Other,
6+
AutomotiveNavigation,
7+
Fitness,
8+
OtherNavigation
9+
}
10+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class Address
6+
{
7+
public double Latitude { get; set; }
8+
public double Longitude { get; set; }
9+
public string CountryCode { get; set; }
10+
public string CountryName { get; set; }
11+
public string FeatureName { get; set; }
12+
public string PostalCode { get; set; }
13+
public string SubLocality { get; set; }
14+
public string Thoroughfare { get; set; }
15+
public string SubThoroughfare { get; set; }
16+
public string Locality { get; set; }
17+
public string AdminArea { get; set; }
18+
public string SubAdminArea { get; set; }
19+
20+
public Address(Address address)
21+
{
22+
if (address == null)
23+
throw new ArgumentNullException(nameof(address));
24+
25+
CountryCode = address.CountryCode;
26+
CountryName = address.CountryName;
27+
Latitude = address.Latitude;
28+
Longitude = address.Longitude;
29+
FeatureName = address.FeatureName;
30+
PostalCode = address.PostalCode;
31+
SubLocality = address.SubLocality;
32+
Thoroughfare = address.Thoroughfare;
33+
SubThoroughfare = address.SubThoroughfare;
34+
SubAdminArea = address.SubAdminArea;
35+
AdminArea = address.AdminArea;
36+
}
37+
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace eShopOnContainers.Core.Models.Location
2+
{
3+
public enum GeolocationError
4+
{
5+
PositionUnavailable,
6+
Unauthorized
7+
}
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class GeolocationException : Exception
6+
{
7+
public GeolocationError Error { get; private set; }
8+
9+
public GeolocationException(GeolocationError error)
10+
: base("A geolocation error occured: " + error)
11+
{
12+
if (!Enum.IsDefined(typeof(GeolocationError), error))
13+
throw new ArgumentException("error is not a valid GelocationError member", "error");
14+
15+
Error = error;
16+
}
17+
18+
public GeolocationException(GeolocationError error, Exception innerException)
19+
: base("A geolocation error occured: " + error, innerException)
20+
{
21+
if (!Enum.IsDefined(typeof(GeolocationError), error))
22+
throw new ArgumentException("error is not a valid GelocationError member", "error");
23+
24+
Error = error;
25+
}
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class ListenerSettings
6+
{
7+
public bool AllowBackgroundUpdates { get; set; } = false;
8+
public bool PauseLocationUpdatesAutomatically { get; set; } = true;
9+
public ActivityType ActivityType { get; set; } = ActivityType.Other;
10+
public bool ListenForSignificantChanges { get; set; } = false;
11+
public bool DeferLocationUpdates { get; set; } = false;
12+
public double? DeferralDistanceMeters { get; set; } = 500;
13+
public TimeSpan? DeferralTime { get; set; } = TimeSpan.FromMinutes(5);
14+
}
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class Position
6+
{
7+
public DateTimeOffset Timestamp { get; set; }
8+
public double Latitude { get; set; }
9+
public double Longitude { get; set; }
10+
public double Altitude { get; set; }
11+
public double Accuracy { get; set; }
12+
public double AltitudeAccuracy { get; set; }
13+
public double Heading { get; set; }
14+
public double Speed { get; set; }
15+
16+
public Position()
17+
{
18+
}
19+
20+
public Position(double latitude, double longitude)
21+
{
22+
23+
Timestamp = DateTimeOffset.UtcNow;
24+
Latitude = latitude;
25+
Longitude = longitude;
26+
}
27+
28+
public Position(Position position)
29+
{
30+
if (position == null)
31+
throw new ArgumentNullException("position");
32+
33+
Timestamp = position.Timestamp;
34+
Latitude = position.Latitude;
35+
Longitude = position.Longitude;
36+
Altitude = position.Altitude;
37+
AltitudeAccuracy = position.AltitudeAccuracy;
38+
Accuracy = position.Accuracy;
39+
Heading = position.Heading;
40+
Speed = position.Speed;
41+
}
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class PositionErrorEventArgs : EventArgs
6+
{
7+
public GeolocationError Error { get; private set; }
8+
9+
public PositionErrorEventArgs(GeolocationError error)
10+
{
11+
Error = error;
12+
}
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace eShopOnContainers.Core.Models.Location
4+
{
5+
public class PositionEventArgs : EventArgs
6+
{
7+
public Position Position { get; private set; }
8+
9+
public PositionEventArgs(Position position)
10+
{
11+
if (position == null)
12+
throw new ArgumentNullException("position");
13+
14+
Position = position;
15+
}
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace eShopOnContainers.Core.Models.Permissions
2+
{
3+
public enum Permission
4+
{
5+
Unknown,
6+
Location,
7+
LocationAlways,
8+
LocationWhenInUse
9+
}
10+
}

0 commit comments

Comments
 (0)