首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MapsUI 1.4.0 Xamarin不同版本的Newtonsoft.Json

MapsUI 1.4.0 Xamarin不同版本的Newtonsoft.Json
EN

Stack Overflow用户
提问于 2020-06-26 10:17:55
回答 1查看 116关注 0票数 0

我正在写一个应用程序,你可以在屏幕上显示你的位置。一切正常,但地图只有一个像素线高。有什么解决办法吗?

代码语言:javascript
复制
  <Grid x:Name="MapGrid"
     HorizontalOptions="CenterAndExpand"/>
  <Grid>

这是我的项目的主要cs代码,我没有得到突破错误只是关于包的警告。我的应用程序将很好地启动,只显示一个像素线的地图。

代码语言:javascript
复制
    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;
        }
    }
}
}

这是我添加的一个类,因为它不能正常工作。

代码语言:javascript
复制
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框架一起使用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-26 14:14:48

一切正常,但地图只有一个像素线高。有什么解决办法吗?

要使用Mapsui,不需要创建定制的mapsui视图。将声明行代码添加到xaml文件中,视图将可用。

检查代码:

代码语言:javascript
复制
<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>

How to use Mapsui 2.0.1 with Xamarin.Forms?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62592633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档