postit: tolerate nearby rdv map cache hits
This commit is contained in:
parent
0975db38b3
commit
52be2e6066
2 changed files with 44 additions and 2 deletions
30
src/PostIt/PostIt.Tests/RdvPageTests.cs
Normal file
30
src/PostIt/PostIt.Tests/RdvPageTests.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using PostIt.Views.Commands;
|
||||||
|
|
||||||
|
namespace PostIt.Tests;
|
||||||
|
|
||||||
|
public class RdvPageTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void AreCoordinatesClose_returns_true_for_nearby_points_within_cache_tolerance()
|
||||||
|
{
|
||||||
|
var result = RdvPage.AreCoordinatesClose(
|
||||||
|
48.8566,
|
||||||
|
2.3522,
|
||||||
|
48.85665,
|
||||||
|
2.35225);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AreCoordinatesClose_returns_false_for_points_outside_cache_tolerance()
|
||||||
|
{
|
||||||
|
var result = RdvPage.AreCoordinatesClose(
|
||||||
|
48.8566,
|
||||||
|
2.3522,
|
||||||
|
48.85685,
|
||||||
|
2.3522);
|
||||||
|
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,7 @@ public partial class RdvPage : ContentPage
|
||||||
private const double DefaultLongitude = 2.3522;
|
private const double DefaultLongitude = 2.3522;
|
||||||
private const int DefaultZoomLevel = 4;
|
private const int DefaultZoomLevel = 4;
|
||||||
private const int SelectedZoomLevel = 13;
|
private const int SelectedZoomLevel = 13;
|
||||||
|
internal const double ReverseGeocodingCacheToleranceDegrees = 0.0001;
|
||||||
private static readonly TimeSpan ReverseGeocodingDebounce = TimeSpan.FromMilliseconds(350);
|
private static readonly TimeSpan ReverseGeocodingDebounce = TimeSpan.FromMilliseconds(350);
|
||||||
|
|
||||||
private MapControl? _locationMap;
|
private MapControl? _locationMap;
|
||||||
|
|
@ -183,8 +184,9 @@ public partial class RdvPage : ContentPage
|
||||||
|
|
||||||
private async Task TryResolveAddressAsync(RdvViewModel vm, double latitude, double longitude)
|
private async Task TryResolveAddressAsync(RdvViewModel vm, double latitude, double longitude)
|
||||||
{
|
{
|
||||||
if (_lastResolvedLatitude == latitude
|
if (_lastResolvedLatitude.HasValue
|
||||||
&& _lastResolvedLongitude == longitude
|
&& _lastResolvedLongitude.HasValue
|
||||||
|
&& AreCoordinatesClose(_lastResolvedLatitude.Value, _lastResolvedLongitude.Value, latitude, longitude)
|
||||||
&& !string.IsNullOrWhiteSpace(_lastResolvedAddress))
|
&& !string.IsNullOrWhiteSpace(_lastResolvedAddress))
|
||||||
{
|
{
|
||||||
vm.ApplyResolvedAddress(_lastResolvedAddress);
|
vm.ApplyResolvedAddress(_lastResolvedAddress);
|
||||||
|
|
@ -221,4 +223,14 @@ public partial class RdvPage : ContentPage
|
||||||
vm.IsResolvingAddress = false;
|
vm.IsResolvingAddress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool AreCoordinatesClose(
|
||||||
|
double latitudeA,
|
||||||
|
double longitudeA,
|
||||||
|
double latitudeB,
|
||||||
|
double longitudeB)
|
||||||
|
{
|
||||||
|
return Math.Abs(latitudeA - latitudeB) <= ReverseGeocodingCacheToleranceDegrees
|
||||||
|
&& Math.Abs(longitudeA - longitudeB) <= ReverseGeocodingCacheToleranceDegrees;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue