diff --git a/MapControl/Shared/Location.cs b/MapControl/Shared/Location.cs
index 879832e6..2d970aaf 100644
--- a/MapControl/Shared/Location.cs
+++ b/MapControl/Shared/Location.cs
@@ -10,7 +10,9 @@ namespace MapControl
///
/// A geographic location with latitude and longitude values in degrees.
///
-#if !UWP
+#if WINUI || UWP
+ [Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.Location.Parse")]
+#else
[System.ComponentModel.TypeConverter(typeof(LocationConverter))]
#endif
public class Location : IEquatable
@@ -21,19 +23,12 @@ namespace MapControl
public Location(double latitude, double longitude)
{
- Latitude = latitude;
+ Latitude = Math.Min(Math.Max(latitude, -90d), 90d);
Longitude = longitude;
}
- private double latitude;
-
- public double Latitude
- {
- get => latitude;
- set => latitude = Math.Min(Math.Max(value, -90d), 90d);
- }
-
- public double Longitude { get; set; }
+ public double Latitude { get; }
+ public double Longitude { get; }
public bool Equals(Location location)
{
diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs
index f2bc4e3b..2e378b6e 100644
--- a/MapControl/Shared/MapBase.cs
+++ b/MapControl/Shared/MapBase.cs
@@ -774,14 +774,17 @@ namespace MapControl
if (center != null)
{
- center.Longitude = Location.NormalizeLongitude(center.Longitude);
+ var centerLatitude = center.Latitude;
+ var centerLongitude = Location.NormalizeLongitude(center.Longitude);
- if (center.Latitude < -maxLatitude || center.Latitude > maxLatitude)
+ if (centerLatitude < -maxLatitude || centerLatitude > maxLatitude)
{
- center.Latitude = Math.Min(Math.Max(center.Latitude, -maxLatitude), maxLatitude);
+ centerLatitude = Math.Min(Math.Max(centerLatitude, -maxLatitude), maxLatitude);
resetTransformCenter = true;
}
+ center = new Location(centerLatitude, centerLongitude);
+
SetValueInternal(CenterProperty, center);
if (centerAnimation == null)
diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs
index f933c00b..be0a1ebf 100644
--- a/MapControl/Shared/MapPanel.cs
+++ b/MapControl/Shared/MapPanel.cs
@@ -232,8 +232,8 @@ namespace MapControl
if (location != null)
{
- location.Longitude = parentMap.ConstrainedLongitude(location.Longitude);
- var pos = parentMap.LocationToView(location);
+ var pos = parentMap.LocationToView(
+ new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude)));
if (pos.HasValue)
{
diff --git a/SampleApps/UniversalApp/MainPage.xaml b/SampleApps/UniversalApp/MainPage.xaml
index d64c04e6..36350d9c 100644
--- a/SampleApps/UniversalApp/MainPage.xaml
+++ b/SampleApps/UniversalApp/MainPage.xaml
@@ -97,14 +97,12 @@
-
-
-
-
-
-
-
-
+
diff --git a/SampleApps/WinUiApp/MainWindow.xaml b/SampleApps/WinUiApp/MainWindow.xaml
index 3820e41c..5bf1b2e2 100644
--- a/SampleApps/WinUiApp/MainWindow.xaml
+++ b/SampleApps/WinUiApp/MainWindow.xaml
@@ -112,14 +112,12 @@
-
-
-
-
-
-
-
-
+