eestein
eestein

Reputation: 5114

Xamarin.Forms Maps crashing app

I'm having a hard time trying to show a map on my Xamarin Forms app. This is the error I get everytime I open the page with the map:

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#

This is the code for creating the page:

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

I'm saying the problem is the map, because if I change the "new Map" line for a Label, for instance, it works.

I'm instantiating the Maps FW as said here: 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());
}

Upvotes: 1

Views: 3068

Answers (2)

Yksh
Yksh

Reputation: 3306

Hold short keys Ctrl+Alt+E to open Exceptions in Visual Studio.

Upvotes: 2

Pete
Pete

Reputation: 4746

I tried your solution for Android, and yes it did throw an Exception.

In the Debug --> Exceptions dialog box, if you click the Thrown checkbox for Common Language Runtime Exceptions you will get a more meaningful description of the exception to be resolved.

enter image description here

The exception detail thrown is:

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

Looking at your AndroidManifest.xml you have no keys defined / capabilities.

Refer to this link that will discuss how to configure your Xamarin.Forms application to handle Maps integration as you appear to be missing some things.

There is more detail on my other StackOverflow answer here that details how to create the API key for Andorid.

Upvotes: 4

Related Questions