postit: tolerate nearby rdv map cache hits
This commit is contained in:
parent
bc162b8a05
commit
247c100344
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 int DefaultZoomLevel = 4;
|
||||
private const int SelectedZoomLevel = 13;
|
||||
internal const double ReverseGeocodingCacheToleranceDegrees = 0.0001;
|
||||
private static readonly TimeSpan ReverseGeocodingDebounce = TimeSpan.FromMilliseconds(350);
|
||||
|
||||
private MapControl? _locationMap;
|
||||
|
|
@ -183,8 +184,9 @@ public partial class RdvPage : ContentPage
|
|||
|
||||
private async Task TryResolveAddressAsync(RdvViewModel vm, double latitude, double longitude)
|
||||
{
|
||||
if (_lastResolvedLatitude == latitude
|
||||
&& _lastResolvedLongitude == longitude
|
||||
if (_lastResolvedLatitude.HasValue
|
||||
&& _lastResolvedLongitude.HasValue
|
||||
&& AreCoordinatesClose(_lastResolvedLatitude.Value, _lastResolvedLongitude.Value, latitude, longitude)
|
||||
&& !string.IsNullOrWhiteSpace(_lastResolvedAddress))
|
||||
{
|
||||
vm.ApplyResolvedAddress(_lastResolvedAddress);
|
||||
|
|
@ -221,4 +223,14 @@ public partial class RdvPage : ContentPage
|
|||
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