I am writing a app where you can show your location on the screen. Everything works fine but the map is just one pixel line high. Is there a solution for this?
<Grid x:Name="MapGrid"
HorizontalOptions="CenterAndExpand"/>
<Grid>
This is the main cs code of my project, i dont get breaking errors just warnings about packages. My app will start just fine just showing just one pixel line of the map.
using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Essentials;
using Mapsui.Utilities;
using Mapsui.Projection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
private MapsuiView mapControl;
public MainPage()
{
InitializeComponent();
mapControl = new MapsuiView();
mapControl.NativeMap.Layers.Add(OpenStreetMap.CreateTileLayer());
MapGrid.Children.Add(mapControl);
Device.StartTimer(TimeSpan.FromSeconds(2), () =>
{
GoToLocation();
return true;
});
async void GoToLocation()
{
Location location = await getLocation();
if (location != null)
{
var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(location.Longitude, location.Latitude);
mapControl.NativeMap.NavigateTo(sphericalMercatorCoordinate);
mapControl.NativeMap.NavigateTo(mapControl.NativeMap.Resolutions[15]);
}
}
async Task<Location> getLocation()
{
Location location = null;
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Best);
location = await Geolocation.GetLocationAsync(request);
if(location != null)
{
Console.WriteLine($"Latitude: {location.Latitude}, " +
$"Longitude: {location.Longitude}, " +
$"Altitude: {location.Altitude}, " +
$"Accuracy: {location.Accuracy}");
}
}
catch (FeatureNotSupportedException fnsEx)
{
Console.WriteLine(fnsEx.ToString());
}
catch (FeatureNotEnabledException fneEx)
{
Console.WriteLine(fneEx.ToString());
}
catch (PermissionException pEx)
{
Console.WriteLine(pEx.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Overige fout: " + ex.ToString());
}
return location;
}
}
}
}
This is a class which i added because it wouldn't work otherwise.
using System;
using System.Collections.Generic;
using System.Text;
namespace mobile_83504_3
{
public class MapsuiView : Xamarin.Forms.View
{
public Mapsui.Map NativeMap { get; }
protected internal MapsuiView()
{
NativeMap = new Mapsui.Map();
}
}
}
I'm using MapsUI 1.4.0 and it's trying to connect to a Newtonsoft.Json 9.0.0 that coudn't be found. so it takes 9.0.1, i don't know if that is the error but that is one of the few warnings that i get. alongside with a .NET framework that might not be fully compatible.