Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
GH-676 Require To Check GPS Location is Fake Or Not In GeoLocation (#677
Browse files Browse the repository at this point in the history
)

* Added  bool IsFromMockProvider in Location class

* Checkin

* csproj original

* Revert "csproj original"

This reverts commit 6302b95.

* Revert "Checkin"

This reverts commit 0881e4f.

* Revert "Added  bool IsFromMockProvider in Location class"

This reverts commit e56d940.

* Revert the Xamarin.Essentials.csproj and Samples.Android.csproj to original;

Adjust the property IsFromMockProvider in Location.shared and LocationExetensions.

* Edited sample to show if the location is from moking provider.

* Update docs
  • Loading branch information
pictos authored and jamesmontemagno committed Jan 28, 2019
1 parent d109e87 commit c68e7cf
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Samples/Samples/ViewModel/GeolocationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ string FormatLocation(Location location, Exception ex = null)
$"Heading: {(location.Course.HasValue ? location.Course.Value.ToString() : notAvailable)}\n" +
$"Speed: {(location.Speed.HasValue ? location.Speed.Value.ToString() : notAvailable)}\n" +
$"Date (UTC): {location.Timestamp:d}\n" +
$"Time (UTC): {location.Timestamp:T}";
$"Time (UTC): {location.Timestamp:T}" +
$"Moking Provider: {location.IsFromMockProvider}";
}

public override void OnDisappearing()
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Essentials/Types/Location.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public Location(Location point)

public double? Course { get; set; }

public bool IsFromMockProvider { get; set; }

public static double CalculateDistance(double latitudeStart, double longitudeStart, Location locationEnd, DistanceUnits units) =>
CalculateDistance(latitudeStart, longitudeStart, locationEnd.Latitude, locationEnd.Longitude, units);

Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Essentials/Types/LocationExtensions.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal static Location ToLocation(this AndroidLocation location) =>
Timestamp = location.GetTimestamp().ToUniversalTime(),
Accuracy = location.HasAccuracy ? location.Accuracy : default(float?),
Course = location.HasBearing ? location.Bearing : default(double?),
Speed = location.HasSpeed ? location.Speed : default(double?)
Speed = location.HasSpeed ? location.Speed : default(double?),
IsFromMockProvider = location.IsFromMockProvider
};

static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Essentials/Types/LocationExtensions.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal static Location ToLocation(this CLLocation location) =>
Accuracy = location.HorizontalAccuracy,
Timestamp = location.Timestamp.ToDateTime(),
Course = location.Course < 0 ? default(double?) : location.Course,
Speed = location.Speed < 0 ? default(double?) : location.Speed
Speed = location.Speed < 0 ? default(double?) : location.Speed,
IsFromMockProvider = DeviceInfo.DeviceType == DeviceType.Virtual
};

internal static DateTimeOffset ToDateTime(this NSDate timestamp)
Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Essentials/Types/LocationExtensions.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ internal static Location ToLocation(this Geoposition location) =>
Altitude = location.Coordinate.Point.Position.Altitude,
Accuracy = location.Coordinate.Accuracy,
Speed = (!location.Coordinate.Speed.HasValue || double.IsNaN(location.Coordinate.Speed.Value)) ? default : location.Coordinate.Speed,
Course = (!location.Coordinate.Heading.HasValue || double.IsNaN(location.Coordinate.Heading.Value)) ? default : location.Coordinate.Heading
Course = (!location.Coordinate.Heading.HasValue || double.IsNaN(location.Coordinate.Heading.Value)) ? default : location.Coordinate.Heading,
IsFromMockProvider = false
};

internal static Location ToLocation(this Geocoordinate coordinate) =>
Expand Down
62 changes: 48 additions & 14 deletions docs/en/Xamarin.Essentials/Location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<Interfaces />
<Docs>
<summary>The latitude, longitude, and time information reported by the device.</summary>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
Expand All @@ -27,7 +28,8 @@
<Parameters />
<Docs>
<summary>Constructor for a location.</summary>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
Expand All @@ -45,7 +47,8 @@
<Docs>
<param name="point">Location to copy values from.</param>
<summary>Constructor for a location.</summary>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
Expand All @@ -65,7 +68,8 @@
<param name="latitude">Default latitude for location.</param>
<param name="longitude">Default longitude for location.</param>
<summary>Constructor for a location.</summary>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
Expand All @@ -87,7 +91,8 @@
<param name="longitude">Default longitude for location.</param>
<param name="timestamp">Timestamp for the location (Utc based).</param>
<summary>Constructor for a location.</summary>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Accuracy">
Expand All @@ -105,7 +110,8 @@
<Docs>
<summary>Gets or sets the accuracy (in meters) of the location.</summary>
<value>The location accuracy.</value>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Altitude">
Expand Down Expand Up @@ -149,7 +155,8 @@
<param name="units">Units to return.</param>
<summary>Calculate distance between two locations.</summary>
<returns>Distance between two locations in the unit selected.</returns>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="CalculateDistance">
Expand Down Expand Up @@ -177,7 +184,8 @@
<param name="units">Unit to return.</param>
<summary>Calculate distance between two locations.</summary>
<returns>Distance calculated.</returns>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="CalculateDistance">
Expand Down Expand Up @@ -205,7 +213,8 @@
<param name="units">Unit to use.</param>
<summary>Calculate distance between two locations.</summary>
<returns>Distance calculated.</returns>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="CalculateDistance">
Expand Down Expand Up @@ -235,7 +244,8 @@
<param name="units">Units to return.</param>
<summary>Calculate distance between two locations.</summary>
<returns>Distance between two locations in the unit selected.</returns>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Course">
Expand All @@ -258,6 +268,26 @@
</remarks>
</Docs>
</Member>
<Member MemberName="IsFromMockProvider">
<MemberSignature Language="C#" Value="public bool IsFromMockProvider { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsFromMockProvider" />
<MemberSignature Language="DocId" Value="P:Xamarin.Essentials.Location.IsFromMockProvider" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Xamarin.Essentials</AssemblyName>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Inform if location is from GPS or from Mock.</summary>
<value>True if is from Mock and False if from GPS.</value>
<remarks>
<para />
</remarks>
</Docs>
</Member>
<Member MemberName="Latitude">
<MemberSignature Language="C#" Value="public double Latitude { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance float64 Latitude" />
Expand All @@ -273,7 +303,8 @@
<Docs>
<summary>Gets or sets the latitude of location.</summary>
<value>Latitude of the location.</value>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Longitude">
Expand All @@ -291,7 +322,8 @@
<Docs>
<summary>Gets or sets the longitude of location.</summary>
<value>Longitude of the location.</value>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Speed">
Expand All @@ -309,7 +341,8 @@
<Docs>
<summary>Speed in meters per second.</summary>
<value>Speed measured by the device..</value>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Timestamp">
Expand All @@ -327,7 +360,8 @@
<Docs>
<summary>Gets or sets the timestamp of the location.</summary>
<value>UTC timestamp.</value>
<remarks></remarks>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="ToString">
Expand Down

0 comments on commit c68e7cf

Please sign in to comment.