加载页面时,Xamarin Map崩溃了

时间:2017-10-26 14:09:37

标签: c# android xamarin xamarin.forms maps

编辑:问题因为安卓而被修复,我忘记添加API键到元数据

我正在尝试为我的Xamarin项目添加一个地图用于Anroid和UWP,但是当我的地图完成后,加载应用程序崩溃并且我得到的唯一异常消息是:

An unhandled exception occured. occurred

我尝试通过使用断点查看代码来找到解决方案,但它似乎只是通过代码很好并且在它再次抛出异常之后立即执行。

这个问题似乎每次都发生在每个平台上(没有经过iOS测试,但我还是不会用它),而我则遵循Xamarin关于Xamarin.Forms.Maps的教程。< / p>

这是.xaml.cs文件的代码(注释掉的部分是我尝试过的另一种方法,结果相同):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.Maps;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace MuffinAppHybrid
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MapPage : ContentPage
    {
        public MapPage()
        {
            InitializeComponent();
            //Map map = new Map(
            //MapSpan.FromCenterAndRadius(
            //        new Position(37, -122), Distance.FromMiles(0.3)))
            //{
            //    IsShowingUser = true,
            //    HeightRequest = 100,
            //    WidthRequest = 960,
            //    VerticalOptions = LayoutOptions.FillAndExpand
            //};
            //StackLayout stack = new StackLayout { Spacing = 0 };
            //stack.Children.Add(map);
            //Content = stack;
        }
    }
}

这是.xaml文件的代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             x:Class="MuffinAppHybrid.MapPage">
    <ContentPage.Content>
        <StackLayout VerticalOptions="StartAndExpand" Padding="30">
            <maps:Map WidthRequest="320" HeightRequest="200"
            x:Name="MyMap"
            IsShowingUser="true"
            MapType="Street"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

我真的不确定出现了什么问题,因为异常消息几乎什么也没说。我希望有人可以提前帮助我。

编辑1 - LogCat的打印屏幕: enter image description here

编辑2 - 导航到页面:

问题也可能出现在Map页面的导航栏中,该代码可在此处找到:

private async void GoToMap(object sender, EventArgs e)
{
    ContentPage page = new MapPage();
    page.Title = "Muffin Map";
    await Navigation.PushAsync(page);
}

0 个答案:

没有答案