Amrish Shah
Amrish Shah

Reputation: 1

Xamarin Forms Google Maps is not getting displayed on android mobile

Xamarin Forms Google Map is not getting displayed on mobile. it is showing blank screen on mobile. I am not sure what is wrong. i have given the correct Android Key and SHA1 cert also. still it is showing blank screen

Below is the code of 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:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
             xmlns:local="clr-namespace:XApp_MAP"
             x:Class="XApp_MAP.MainPage">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />

            <maps:Map Grid.Row="1" x:Name="map"
                      InitialCameraUpdate="35.71, 139.81, 8, 30, 0"
                      VerticalOptions="FillAndExpand" />
        </StackLayout>

    </ContentPage.Content>

Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.xapp_map" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" />
    <application android:label="xappmap.android">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyA81eVj7WmkfsGqqwVnkiz32g9MBdTyxKQ" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.MAPS_RECEIVE" />
    <permission android:name="android.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
</manifest>

Upvotes: 0

Views: 1228

Answers (2)

Techy Hern&#225;ndez
Techy Hern&#225;ndez

Reputation: 149

I was having the same problem, although I was following all steps from this guide: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/map/setup

My problem was that the map it once showed, and then I tried again like a month after and was only showing the Google icon below.

My problem was that I switch computers, so even if my API Key was the same the SHA1 was different now, I just got it from the new pc and updated it in the Console Cloud Credentials.

After that, problem solved.

Here is a useful link: https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/obtaining-a-google-maps-api-key?tabs=windows

Upvotes: 1

Manuel Delgado
Manuel Delgado

Reputation: 1

I think you may have solved your problem long ago, but I put what was my problem to maybe help someone else.

Xamarin.FormsGoogleMaps.Init(this, bundle); // initialize for Xamarin.Forms.GoogleMaps

Make sure you initialize Xamarin Forms Google Maps (with that line of code above) in the method OnCreate inside the MainActivity.cs of your Xamarin Android project. Then, if you have all the configuration done correctly, it should work.

Upvotes: 0

Related Questions