Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />
like image 575
gmn Avatar asked Oct 29 '25 07:10

gmn


2 Answers

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.

like image 198
Mike Ma Avatar answered Oct 31 '25 22:10

Mike Ma


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.

like image 24
p90n33r Avatar answered Oct 31 '25 22:10

p90n33r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!