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

Implement vertical accuracy in GeoLocation API #1103

Merged
merged 4 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Samples/Samples/ViewModel/GeolocationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ string FormatLocation(Location location, Exception ex = null)
return
$"Latitude: {location.Latitude}\n" +
$"Longitude: {location.Longitude}\n" +
$"Accuracy: {location.Accuracy}\n" +
$"HorizontalAccuracy: {location.Accuracy}\n" +
$"Altitude: {(location.Altitude.HasValue ? location.Altitude.Value.ToString() : notAvailable)}\n" +
$"VerticalAccuracy: {(location.VerticalAccuracy.HasValue ? location.VerticalAccuracy.Value.ToString() : notAvailable)}\n" +
$"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" +
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Essentials/Types/Location.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public Location(Location point)

public double? Accuracy { get; set; }

public double? VerticalAccuracy { get; set; }

public double? Speed { get; set; }

public double? Course { get; set; }
Expand Down Expand Up @@ -88,6 +90,7 @@ public static double CalculateDistance(
public override string ToString() =>
$"{nameof(Latitude)}: {Latitude}, {nameof(Longitude)}: {Longitude}, " +
$"{nameof(Altitude)}: {Altitude ?? 0}, {nameof(Accuracy)}: {Accuracy ?? 0}, " +
$"{nameof(VerticalAccuracy)}: {VerticalAccuracy ?? 0}, " +
$"{nameof(Speed)}: {Speed ?? 0}, {nameof(Course)}: {Course ?? 0}, " +
$"{nameof(Timestamp)}: {Timestamp}";
}
Expand Down
6 changes: 6 additions & 0 deletions Xamarin.Essentials/Types/LocationExtensions.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ internal static Location ToLocation(this AndroidLocation location) =>
Altitude = location.HasAltitude ? location.Altitude : default(double?),
Timestamp = location.GetTimestamp().ToUniversalTime(),
Accuracy = location.HasAccuracy ? location.Accuracy : default(float?),
VerticalAccuracy =
#if __ANDROID_26__
location.HasVerticalAccuracy ? location.VerticalAccuracyMeters : default(float?),
#else
default(float?),
#endif
Course = location.HasBearing ? location.Bearing : default(double?),
Speed = location.HasSpeed ? location.Speed : default(double?),
IsFromMockProvider = Platform.HasApiLevel(global::Android.OS.BuildVersionCodes.JellyBeanMr2) ? location.IsFromMockProvider : false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal static Location ToLocation(this CLLocation location) =>
Longitude = location.Coordinate.Longitude,
Altitude = location.VerticalAccuracy < 0 ? default(double?) : location.Altitude,
Accuracy = location.HorizontalAccuracy,
VerticalAccuracy = location.VerticalAccuracy,
Timestamp = location.Timestamp.ToDateTime(),
#if __iOS__ || __WATCHOS__
Course = location.Course < 0 ? default(double?) : location.Course,
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Essentials/Types/LocationExtensions.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal static Location ToLocation(this Geoposition location) =>
Timestamp = location.Coordinate.Timestamp,
Altitude = location.Coordinate.Point.Position.Altitude,
Accuracy = location.Coordinate.Accuracy,
VerticalAccuracy = location.Coordinate.AltitudeAccuracy,
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,
IsFromMockProvider = false
Expand All @@ -44,6 +45,7 @@ internal static Location ToLocation(this Geocoordinate coordinate) =>
Timestamp = coordinate.Timestamp,
Altitude = coordinate.Point.Position.Altitude,
Accuracy = coordinate.Accuracy,
VerticalAccuracy = coordinate.AltitudeAccuracy,
Speed = (!coordinate.Speed.HasValue || double.IsNaN(coordinate.Speed.Value)) ? default : coordinate.Speed,
Course = (!coordinate.Heading.HasValue || double.IsNaN(coordinate.Heading.Value)) ? default : coordinate.Heading
};
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-android.xml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-ios.xml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-tvos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-uwp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-watchos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@
<Member Id="P:Xamarin.Essentials.Location.Longitude" />
<Member Id="P:Xamarin.Essentials.Location.Speed" />
<Member Id="P:Xamarin.Essentials.Location.Timestamp" />
<Member Id="P:Xamarin.Essentials.Location.VerticalAccuracy" />
</Type>
<Type Name="Xamarin.Essentials.LocationExtensions" Id="T:Xamarin.Essentials.LocationExtensions">
<Member Id="M:Xamarin.Essentials.LocationExtensions.CalculateDistance(Xamarin.Essentials.Location,System.Double,System.Double,Xamarin.Essentials.DistanceUnits)" />
Expand Down
24 changes: 22 additions & 2 deletions docs/en/Xamarin.Essentials/Location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
<ReturnType>System.Nullable&lt;System.Double&gt;</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the accuracy (in meters) of the location.</summary>
<value>The location accuracy.</value>
<summary>Gets or sets the horizontal accuracy (in meters) of the location.</summary>
<value>The horizontal accuracy of the location.</value>
<remarks>
<para />
</remarks>
Expand Down Expand Up @@ -397,5 +397,25 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="VerticalAccuracy">
<MemberSignature Language="C#" Value="public Nullable&lt;double&gt; VerticalAccuracy { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Nullable`1&lt;float64&gt; VerticalAccuracy" />
<MemberSignature Language="DocId" Value="P:Xamarin.Essentials.Location.VerticalAccuracy" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.Essentials</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Nullable&lt;System.Double&gt;</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the vertical accuracy (in meters) of the location.</summary>
<value>The vertical accuracy of the location.</value>
<remarks>
<para />
</remarks>
</Docs>
</Member>
</Members>
</Type>