'Xamarin Google Maps Blank

I've been following:

https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/

and

https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/

in order to use Google maps in an android app. And I cannot get the maps to show in my application at all. It always shows a blank page. I'm also not seeing any errors.

I have:

  1. Added the necessary permissions to my android manifest
  2. Enabled the API in the apis page online.
  3. Added credentials based on using the local debug keystore
  4. Added the map as a mapfragment on my main activity page.

Everything online is pointing at the debug key being incorrect but I must have tried everything I can with this one and it still doesn't work. Could it be picking a different one up somehow?

Also, I'm not sure of the significance, but the mapfragment is always null in on resume when I try to access it.

Keystore command:

keytool -list -v -keystore "C:\Users\<My User folder>\AppData\Local\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Permissions in manifest (With AppName and key hidden):

  <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
    <!-- We need to be able to download map tiles and access Google Play Services-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Allow the application to access Google web-based services. -->
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!-- Google Maps for Android v2 will cache map tiles on external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Permission to receive remote notifications from Google Play Services -->
    <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
    <permission android:name="APPNAME.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
    <uses-permission android:name="APPNAME.permission.MAPS_RECEIVE" />
    <!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="<app name>">
        <!-- Put your Google Maps V2 API Key here. -->
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MYKEY" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>

Main activity contents:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />


Solution 1:[1]

in order to use Google maps in an android app. And I cannot get the maps to show in my application at all. It always shows a blank page. I'm also not seeing any errors.

This is probably caused by following reasons:

  1. Check the reference here How can I create a keystore? Once the app is signed then the map won't work.

  2. When you use a different computer to build the app please get the SHA-1 from the new computer.

  3. Do not use the keystore that is generated by Java. Please use the keystore that is generated by Visual Studio. It is in C:\Users\username\AppData\Local\Xamarin\Mono for Android/.

  4. Use the emulator that contains Google API.

  5. Do not forget to enable Google API in Google Console.

And this Xamarin Android Google Map demo should be helpful for you. I have tried this demo with my own keystore and API_KEY and it works.

Solution 2:[2]

I have solved this problem by configuring my project in Google Console to Enable Places SDK for Android And Maps SDK for Android

wait for few minutes and BOOM !

Sometimes you might need to reinstall the app on your device.

Solution 3:[3]

If you enable Google Play App Signing then you need to use the keystore detail that will be provided by after you have uploaded your apk.

Release management -> App signing (tab)

App signing certificate is what you need. Copy the SHA-1 certificate fingerprint.

Solution 4:[4]

The current answer didn't quite work for me. I misunderstood what the docs -https://docs.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/obtaining-a-google-maps-api-key?tabs=windows - meant when it says:

This API KEY must be the API KEY from the google developer console and not the SHA-1 that you used to generate your keystore. While this might have been obvious to most of you, hopefully this helps some other user in the future.

Solution 5:[5]

Just for collection.. I faced with the same problem but after load my bundle file application through the Google Play Console... I signed my application by my release keystore key and ... nothing. maps doesn't appeared in application downloaded and installing from Google Play. So solution is in this archive topic (in the last post): https://social.msdn.microsoft.com/Forums/en-US/ef283f57-676a-498a-afa6-74ac237391f1/google-maps-blank-on-release-mode?forum=xamarinandroid

"In my case, it turned out that Google Play Console signed the released apk with its own Google certificate, setting a SHA1 different to the one used to authorize the Google Maps API."

It's exactly weird... but any way.. After i download my app from bundle explorer and check SHA1 I was "surprised"... Just added this "new" SHA1 in my Google Cloud Platform for my "Restrict usage to your Android apps" section.. And Maps appeared for all versions.. That's all. I will be glad if it help someone

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 p90n33r
Solution 3 patJnr
Solution 4 Yoman allo
Solution 5 Serg Vorontsov