MapsUI 1.4.0 Xamarin 差异版本 Newtonsoft.Json
MapsUI 1.4.0 Xamarin differemce versions Newtonsoft.Json
我正在编写一个可以在屏幕上显示您的位置的应用程序。一切正常,但地图只有一个像素线高。有解决办法吗?
<Grid x:Name="MapGrid"
HorizontalOptions="CenterAndExpand"/>
<Grid>
这是我项目的主要 cs 代码,我没有遇到重大错误,只是收到有关包的警告。我的应用程序将正常启动,只显示地图的一条像素线。
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;
}
}
}
}
这是我添加的 class,因为否则它无法工作。
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();
}
}
}
我正在使用 MapsUI 1.4.0,它正在尝试连接到找不到的 Newtonsoft.Json 9.0.0。所以它需要 9.0.1,我不知道这是否是错误,但这是我收到的为数不多的警告之一。以及可能不完全兼容的 .NET 框架。
Everything works fine but the map is just one pixel line high. Is there a solution for this?
要使用 Mapsui,无需创建自定义 mapsui 视图。将声明行代码添加到xaml文件中,视图将可用。
查看代码:
<ContentPage
...
xmlns:mapsui="clr-namespace:Mapsui.UI.Forms;assembly=Mapsui.UI.Forms">
<StackLayout>
<mapsui:MapView x:Name="mapView"
VerticalOptions="FillAndExpand"
HorizontalOptions="Fill"
BackgroundColor="Gray" />
</StackLayout>
</ContentPage>
我正在编写一个可以在屏幕上显示您的位置的应用程序。一切正常,但地图只有一个像素线高。有解决办法吗?
<Grid x:Name="MapGrid"
HorizontalOptions="CenterAndExpand"/>
<Grid>
这是我项目的主要 cs 代码,我没有遇到重大错误,只是收到有关包的警告。我的应用程序将正常启动,只显示地图的一条像素线。
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;
}
}
}
}
这是我添加的 class,因为否则它无法工作。
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();
}
}
}
我正在使用 MapsUI 1.4.0,它正在尝试连接到找不到的 Newtonsoft.Json 9.0.0。所以它需要 9.0.1,我不知道这是否是错误,但这是我收到的为数不多的警告之一。以及可能不完全兼容的 .NET 框架。
Everything works fine but the map is just one pixel line high. Is there a solution for this?
要使用 Mapsui,无需创建自定义 mapsui 视图。将声明行代码添加到xaml文件中,视图将可用。
查看代码:
<ContentPage
...
xmlns:mapsui="clr-namespace:Mapsui.UI.Forms;assembly=Mapsui.UI.Forms">
<StackLayout>
<mapsui:MapView x:Name="mapView"
VerticalOptions="FillAndExpand"
HorizontalOptions="Fill"
BackgroundColor="Gray" />
</StackLayout>
</ContentPage>