Search code examples
c#xamarin.formsmobilexamarin.androidmapbox

Mapbox Xamarin.Forms black map on Android (Naxam.Mapbox.Form)


I have created an empty Xamarin.Forms project. Installed all required nugets. Added accessToken to MainActivity.OnCreate. Added a map to the start page and got a black screen.

(And maybe someone has a working Xamarin.Forms project using Naxam.Mapbox.Form?)

MainActivity:

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

    Com.Mapbox.Mapboxsdk.Mapbox.GetInstance(this, MAPBOX_TOKEN);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
}

MainPage.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:local="clr-namespace:Naxam.Controls.Forms;assembly=Naxam.Mapbox.Forms"
             x:Class="MapBoxEmpty.MainPage">

    <StackLayout>
        <local:MapView x:Name="map" 
                       VerticalOptions="FillAndExpand" 
                       HorizontalOptions="FillAndExpand"
                       MapStyle="LIGHT" 
        />
    </StackLayout>

</ContentPage>

App:

enter image description here

What's wrong?

P.s. Haven't looked at iOS.

Dropmefiles - Test project


Solution

  • The solution was to define the style of map in the page's code-behind file, not in the xaml...