【问题标题】:Xamarin.forms.maps not visible in UWPXamarin.forms.maps 在 UWP 中不可见
【发布时间】:2017-04-05 19:18:15
【问题描述】:

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

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

但是,地图在部署时不可见。我也添加了一些引脚,我看到的是一些带有引脚的蓝屏。我尝试了很多选择,但还没有找到运气。 下面是调用maps的代码sn-p:

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);

我做错了吗?或者是否有任何缺失的参考资料我应该添加以使这项工作?请帮帮我。 P.S- 相同的解决方案在我同事的机器上加载地图,但在其他人的机器上不起作用。

问候, 斯瓦提

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

UWP Nuget package reference

【问题讨论】:

  • 你能分享你的 UWP 配置吗?从文档来看,您可能需要一些在每个平台中具有适当设置的服务定位器魔法:developer.xamarin.com/guides/xamarin-forms/user-interface/map/…
  • 谢谢乔。我不确定如何找到 UWP 配置。通过在此处添加我的 UWP 引用的屏幕截图更新了我的查询。
  • 也如链接中所建议的(由您推荐),我已经在使用身份验证令牌密钥:(
  • 你检查过official sample here吗?它在我身边工作,根据您的描述:“相同的解决方案在我同事的机器上加载地图,但在其他机器上不起作用。”,你的意思是在某些机器上你的代码可以工作而其他机器不行?

标签: uwp xamarin.forms invisible


【解决方案1】:

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

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

rootFrame.NavigationFailed += OnNavigationFailed;

添加 列出程序集ToInclude = new List();

        //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 行替换了代码中对初始化程序的保存现有调用。

【讨论】:

    【解决方案2】:

    您需要在您的 Google API 控制台上启用 google map API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      相关资源
      最近更新 更多