Xamarin.Forms 地图应用崩溃

Xamarin.Forms Maps crashing app

我很难尝试在我的 Xamarin Forms 应用程序上显示地图。这是我每次打开带有地图的页面时遇到的错误:

0x29 in System.Diagnostics.Debugger.Mono_UnhandledException_internal    C#
0x1 in System.Diagnostics.Debugger.Mono_UnhandledException  C#
0x6 in Android.Runtime.UncaughtExceptionHandler.UncaughtException at /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Runtime/UncaughtExceptionHandler.cs:35,4 C#
0x1C in Java.Lang.Thread.IUncaughtExceptionHandlerInvoker.n_UncaughtException_Ljava_lang_Thread_Ljava_lang_Throwable_ at /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.Thread.cs:221,5 C#
0x1D in object.28d67210-c8ee-4f17-9d83-36104107982d C#

这是创建页面的代码:

var topLayout = new StackLayout
{
    Children =
    {
        new Map(MapSpan.FromCenterAndRadius(new Position(37,-122), Distance.FromMiles(0.3)))
        {
            IsShowingUser = true,
            HeightRequest = 100,
            VerticalOptions = LayoutOptions.FillAndExpand
        }
    }
};

var bottomLayout = new StackLayout { Children = { ... }  }; //shortened for readability

Content = new StackLayout
{
    Children = { topLayout, bottomLayout }
};

我是说问题出在地图上,因为如果我更改标签的 "new Map" 行,例如,它会起作用。

我正在实例化 Maps FW,如此处所述:http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/maps/

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);
    Xamarin.FormsMaps.Init(this, bundle);
    LoadApplication(new FullHelp.App());
}

我尝试了 Android 的解决方案,是的,它确实抛出了 Exception

Debug --> Exceptions 对话框中,如果单击 Common Language Runtime ExceptionsThrown 复选框,您将获得对要解决的异常的更有意义的描述。

抛出的异常详情为:

'Java.Lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:valu…'

查看您的 AndroidManifest.xml 您没有定义键/功能。

参考 this link,它将讨论如何配置您的 Xamarin.Forms 应用程序来处理 Maps 集成,因为您似乎遗漏了一些东西。

我的另一个 Whosebug 回答 here 有更多详细信息,详细说明了如何为 Andorid 创建 API 密钥。

按住短键 Ctrl+Alt+E 打开 Visual Studio.

中的例外