首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin.forms.maps在UWP中不可见

Xamarin.forms.maps在UWP中不可见
EN

Stack Overflow用户
提问于 2016-11-22 15:48:13
回答 2查看 689关注 0票数 0

我是Xamarin.forms的新手,需要使用UWP平台的地图。我已经在我的PCL中安装了Xamarin.Forms.Maps nuget包。并调用了UWP部分的App.xaml.cs中的init函数,如下所示:

Xamarin.Forms.Forms.Init(e);Xamarin.FormsMaps.Init("TokenKey");

但是,地图在部署时不可见。我也添加了一些引脚,我看到的是一些带有引脚的蓝屏。我尝试了很多选择,但还没有找到任何机会。下面是调用map的代码片段:

代码语言:javascript
复制
Map map = new Map(MapSpan.FromCenterAndRadius(new Position(51.5074, 0.1278), Distance.FromMiles(10)));
        map.MapType = Xamarin.Forms.Maps.MapType.Hybrid;
        map.HeightRequest = 700;
        map.WidthRequest = 725;
        map.IsShowingUser = true;
        var position1 = new Position(51.5033, 0.1195);
        var pin1 = new Pin { Type = PinType.Place, Position = position1, Label = "label1", Address = "address1" };
        map.Pins.Add(pin1);
        var position2 = new Position(51.5014, 0.1419);
        var pin2 = new Pin { Type = PinType.Place, Position = position2, Label = "label1", Address = "address1" };
        map.Pins.Add(pin2);
        this.mapGrid.Children.Add(map);

我做错什么了吗?或者,是否有任何我应该添加的缺失引用才能使其正常工作?请帮帮我。附注:同样的解决方案在我同事的机器上加载地图,但在其他机器上不起作用。

向您致敬,Swati

请在下面找到我的UWP参考的屏幕截图:UWP reference screenshot

UWP Nuget package reference

EN

回答 2

Stack Overflow用户

发布于 2017-05-07 00:12:56

您需要使用System.Reflection添加此解决方案才能工作。

对于一些框架和UWP来说,这似乎是一个已知的挑战。在UWP项目的App.Xaml.cs中,在OnLaunched事件中,在以下代码行之后:

代码语言:javascript
复制
rootFrame.NavigationFailed += OnNavigationFailed;

添加列表assembliesToInclude = new List();

代码语言:javascript
复制
        //Now, add all the assemblies your app uses
        assembliesToInclude.Add(typeof(Syncfusion.SfRating.XForms.UWP.SfRatingRenderer).GetTypeInfo().Assembly);
        assembliesToInclude.Add(typeof(Xamarin.Forms.Maps.UWP.MapRenderer).GetTypeInfo().Assembly);

        Xamarin.Forms.Forms.Init(e, assembliesToInclude);

确保这里显示的...Forms.Init行替换了代码中对初始化器的保存现有调用。

票数 0
EN

Stack Overflow用户

发布于 2019-06-02 18:44:05

您需要在google API控制台上启用Google地图API

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

https://stackoverflow.com/questions/40736370

复制
相关文章

相似问题

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