Open Stuart88 opened 4 years ago
Bit of an update to this:
I'm running the same code on a different machine and have found I need to force the map span down to an even smaller size (4000000m seems to work). This is slightly concerning; I guess it depends on screen resolution or something? And this would mean the issue could presumably still appear when the project is released to other devices with different screens.
Sadly it's a bit beyond me at this point, all I can do is continue with my workaround.
It's not a screen size issue, it's an incorrect translation from MapSpan to the Northwest/Southeast coordinates used for the GeoboundingBox constructor.
The renderer isn't taking into account wraparound when translating the values; if the center position of the MapSpan is, say, 89 degrees and the region size is more than 1 degree, it will try to create the GeoboundingBox with a latitude greater than 90 degrees. Which is ... well, that just doesn't work.
Here's an example platform test which currently won't pass:
[Test]
public async Task MapSpanTest()
{
var map = new Map{ };
await Device.InvokeOnMainThreadAsync(() =>
{
using (var renderer = GetRenderer(map))
{
var pos = new Position(89, 179);
var span = MapSpan.FromCenterAndRadius(pos, new Distance(500000));
map.MoveToRegion(span);
}
});
}
Description
UWP map control throws unhandled exception on
MoveToRegion()
for very large map span radius.Steps to Reproduce
Map.MoveToRegion()
for a span with radius greater than 5000000mExpected Behavior
Map zoomed out very far (maximum zoom out?)
Actual Behavior
App crash - UnhandledException
Basic Information
Version with issue: 4.8.0.1451
Last known good version:
IDE: VS2019
Platform Target Frameworks:
Nuget Packages: Xamarin.Forms.Maps 4.8.0.1451
Exception:
System.ArgumentException
(thrown as UnhandledException)Stack Trace:
at Windows.Devices.Geolocation.GeoboundingBox..ctor(BasicGeoposition northwestCorner, BasicGeoposition southeastCorner) at Xamarin.Forms.Maps.UWP.MapRenderer.d25.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.Forms.Maps.UWP.MapRenderer.<b 0_0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__7_0(Object state)
at System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeCore()
Workaround
For UWP runtime platform, check size of radius and adjust to smaller if needed