Monodroid Google Maps API v2 - Error contacting Google servers - android

I am developing a MonoDroid project and can't seem to get past this issue. I am trying to use the MapsAndLocationDemo_v2 project and can't even get the maps to load on the SimpleMapDemo project. I have gone through many SO posts concerning this issue.
The map loads but is white and Application Output states:
[Google Maps Android API] Failed to contact Google servers. Another attempt will be made when connectivity is established.
[Google Maps Android API] Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I built the Google Play Client Services Library by following the instructions in the project README.md.
I generated a new Android Google Maps v2 API Key using the debug.keystore located at:
C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore
and replaced the one in the project manifest.xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="5" android:versionName="4.0" package="com.xamarin.docs.android.mapsandlocationdemo2">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<!-- 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 ndroid: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" />
<!-- 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" />
<!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
<uses-permission android:name="com.xamarin.docs.android.mapsandlocationdemo2.permission.MAPS_RECEIVE" />
<permission android:name="com.xamarin.docs.android.mapsandlocationdemo2.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<application android:label="#string/app_name">
<!-- Put your Google Maps V2 API Key here. This key will not work for you.-->
<!-- See https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key -->
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="xxxxxxxxxxxxxMY_KEY_HERExxxxxxxxxxxxxxx" />
</application>
</manifest>
My Android device is running 4.0.3. Google Play Services is installed and up to date on my device.
Any suggestions would be welcome...

Ensure that you have really signed your application with the same key which you had used to get the API key.
And that the application package is the same as was in API key request.
I've lost a few hours with the problem to find out that there was something wrong with application signature.
I've signed it manually and map appears.

Have a look how to check if your app is signed with valid key - otherwise Google Map will not work correctly, auth will be rejected or other such problems.
Check also logcat which probably prints out the reason of this problem.

Related

Android Studio Emulator: Authentication failed. Timeout while trying to contact the server

I am trying to learn Android development & doing it the first time to do some hands-on to develop my ideas. I want to load the google map with the current location on the emulator.
Referred SE Questions: Failed to load map. Error contacting Google servers. This is probably an authentication issue
Initially, I faced the problem "won't run unless I update google play service in android studio"
The problem got resolved after changing:
compile 'com.google.android.gms:play-services:9.0+
I also corrected API_KEY by generating the API_KEY from the link given in code file. Now I am not getting that error but still not able to load the map on the emulator. These seem to be connection issue & I added the permission in manifest files as well. But the problem still persists. Kindly guide me & provide your valuable suggestions.
google_maps_api.xml
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=6C:42:DD:0A:5D:D3:E4:5E:79:C9:04:81:3A:7A:70:17:25:37:97:96%3Bcom.example.kapilj3.meetmeapp
You can also add your credentials to an existing key, using this line:
6C:42:DD:0A:5D:D3:E4:5E:79:C9:04:81:3A:7A:70:17:25:37:97:96;com.example.kapilj3.meetmeapp
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIza_MY_ACTUAL_KEY</string>
</resources>
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
add this code to your application manifiest

Authorization Failure in Google Maps Android V2

When I try to debug my project I got this error using debug certificate
I already ensure that my package name and SHA-1 corresponds to my api key
Here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.example">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
<!-- 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. -->
<uses-permission android:name="com.example.permission.MAPS_RECEIVE" />
<permission android:name="com.example.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<!-- 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="map" android:icon="#drawable/Icon">
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="map_key" />
</application>
</manifest>
Here's my API KEY
Here's my SHA-1 certificate
I got my SHA-1 using eclipse
By the way I'am using real device in debugging my project, c#, visual studio 2012 and xamarin.android. It only displays white screen with google logo and zoom in and out button. What's wrong with my debug certificate?
If the key is new ( has just been created in Google APIs Console ) it will take some time for it to be available to Google Maps.
Don't worry everything is declared OK, it just takes some time.
Edit : By what is written in the log looks like you have to add the fingerprint for your debug key store : D9595..
Just add a new line in Google APIs console with that fingerprint . Your debug keystore is found at C:\Users\.android\debug.keystore and the default password is : android

Authorization failure while loading google maps v2 android

I am making an android app with google maps:-
My steps:-
Main activity extends Fragment activity
Made a copy of Google play services library and imported it to eclipse.Further added a reference of the library to the project.
Enabled the build target of the project to Google API's 4.4.2
Created a browser key on Google API console.
Created an SHA1 certificate for the app in eclipse using the keytool plugin(Also verifies the key using the traditional command prompt technique and both match).
Created an android Api key on Google API console using the SHA1 key obtained
Issue:- I get a blank map on the screen with the zoom in and zoom out buttons
Here is my code:-
activity_main.xml:-
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/spr_place_type"
/>
AndroidManifest.xml :-
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<permission
android:name="com.strangeworld.locations.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library
android:name="com.google.android.maps"/>
<activity
android:name="com.strangeworld.locatorapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD2LVShEdbQWWV4......"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Log cat:-
01-10 10:33:28.059: E/dalvikvm(2440): Could not find class 'maps.ae.i', referenced from method maps.af.al.a
01-10 10:33:30.039: E/GooglePlayServicesUtil(2440): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-10 10:33:32.909: E/Google Maps Android API(2440): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-10 10:33:32.929: E/Google Maps Android API(2440): Ensure that the following correspond to what is in the API Console: Package Name: com.example.locations, API Key: AIzaSyAZhJllASbTnr......, Certificate Fingerprint: 83033D1ECACA2C88F9AA2.....
While generating the key do i need to spicify the whole package name i.e. com.abcdm.locatorapp or just com.abcdm
Yes you need to mention the package name in the google api console
SHA;complete packagename
Also try regenerating the key
The Google Play services resources were not found. Check your project configuration to ensure that the resources are included
You need to reference the google play servies properly. Check this
Importing google-play-service library showing a red X next to this reference android
Your keystore is not appropriate or package name mistake in google api console, recheck once.
Which type of keystore you are using? If you use debug key and published map looks blank. Use release key to publish.
Google Map Android API v2 can't display map in play store application
mention the entire package name with the key after semicolon ie. com.abcdm.locatorapp

Map won't show with Android Maps API v2, Gradle and Android Studio

I am attempting to add The Maps API v2 for Android to my project that is being built in Android Studio. I am adding the Google Play Services through the build.gradle file and maven (it is being imported through the Google Repository in the SDK Manager). I add the following to my build.gradle file inside of my project:
compile "com.google.android.gms:play-services:3.1.36"
This works near perfectly. I am able to use the APIs in code and reference them in XML. For example, I am using LocationClient to retrieve the users location just fine; I can add com.google.android.gms.MapView to an XML file and it builds and runs perfectly.
The issue is that the map will not display. Now, I have added the following to my manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application ...>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="[MY API KEY HERE]"/>
</application>
I obtained the API key through the use of the debug certificate; I have turned on the "Google Maps Android API v2" in the API Console. Everything appears to be set up just fine, but the map still will not load. Any help?
Checking the documentation here:
Users of this class must forward all the Activity life cycle methods - such as onCreate(), onDestroy(), onResume(), and onPause() - to the corresponding methods in the MapView class.
If you neglect this step you will run into the issue where the map will not load.

Google Maps API V2 'Failed to Load Map. Could not contact Google Servers'

I have checked and double checked my APIkey that I registered on the Google Console however I am still getting the following error:
12-05 16:31:12.940: E/Google Maps Android API(12334): Failed to load map. Could not contact Google servers.
What I am seeing is the zoom in/out buttons and the background for the MapView but no Map???!!!
Any ideas???
Answer
I will post it here because what solved my issue was stated in the comments of the accepted answer below.
It was the READ_GSERVICES permission. For some reason the permission wasn't mentioned on the developer site when it came to using them.
For setting up Google Maps API v2 on Android, make sure that you have completed all of the following steps.
App Key For API Access
When Google asks for the SHA1 fingerprint of your app certificate, you will want most likely want to run this twice, once for your debuging certificate, and once for your publishing certificate.
keytool -list -v -keystore publishcert.keystore
keytool -list -v -keystore ~/.android/debug.keystore
The fingerprint of the app on the market is different then the fingerprint of an app that you are just testing!
Enable the service on the Google API Console
Login to the Google API Console.
On the services page, find Google Maps Android API v2.
Note - Google Maps API v2 is DIFFERENT then Google Maps Android API v2
In the API Access tab, click Create new Android Key
Add your certificate signatures for access to the APIs.
yourrelease-fingerprint;com.example.project.package
yourdebug-fingerprint;com.example.project.package
You will be provided with a generated API Access Key.
You may need to first create an API Project in the API Console
Amend the App Manifest
Add your API Key, inside of the <application> element.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="yourapikey"/>
Add the following permissions:
<permission
android:name="com.example.project.package.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.project.package.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
Add the following feature request:
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
Make sure all below mentioned points are taken care:
1) Wrong service was enabled. Make sure the "Google Maps Android API v2", not "Google Maps API v2" is enabled and re-generate the API key.
2) Add the following elements to your manifest. Replace com.example.mapdemo with the package name of your application.
3) Use of correct certificate and key. Release certificate, which WILL NOT WORK during debugging when you run the app on my phone. You have to use the debugging keystore certificate fingerprint instead.
It could be an issue with the Manifest. The following works for me, specifically permission.MAPS_RECEIVE solved a similar issue I had: zoom buttons and myLocation displayed, but map had no tiles...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.discos2.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.discos2.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.discos2.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:hardwareAccelerated="true">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="__NEW_GOOGLE_MAPS_V2_KEY_GOES_HERE__" />
<activity
android:name=".ui.activities.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
BTW, I'm running Windows 7. I fussed over this for days, until I discovered the following:
I have more than one debug.keystore.
One is at:
C:\android-sdk\.android\debug.keystore
And there's another, at:
C:\Users\David\.android\debug.keystore
Once I found the "C:\Users\David.android\debug.keystore" I did:
keytool -list -alias androiddebugkey -keystore C:\Users\David\.android\debug.keystore -storepass android -keypass android -v
I submitted the resulting SHA1 to google console and got an API-key that works.
Getting the SHA1 from the keystore at "C:\android-sdk.android\debug.keystore" does not work.
I was facing the same issue ; but for me it was keystore issue I was signing it with debug keystore hence Google map api v2 was not able to connect to Google map.
I created a new api key using my-release-keystore.keystore (u can find it at C:\Users\{YOUR_USER_NAME}\.android\my-release-key.keystore) generate SHA1 using keytool available in JDK; copy it and register with google console.
Use api key generated in your applications manifest file. Sign it with my-release-key.keystore will pushing it on device.
You might have enabled the wrong service "Google Maps Android API v2", not "Google Maps API v2"
I had the same problem. I just simply missed this point:
When you list your Google APIs services, there are three Google Maps API available.
Google Maps Android API v2
Google Maps API v2
Google Maps API v3
...
Check that you have Android version (Google Maps Android API v2) enabled, when you code for Android.
Google Maps API v2 was not good enough.
Just create new API key with SHA and most importantly correct package name (like com.example.mapdemo). Use the new generated key in your AndroidManifest.xml.
I guess we need new API key for all new eclipse projects which uses Google maps (as creating new key also requires the package name, which is essentially different for all projects).
After spending many hours, the problem had been eventually solved:
if none of the above helped you solving your problem,
try to put your api key into values/strings.xml
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="#string/map_key"/>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="map_key">YOUR_KEY</string>
</resources>
I did everything what was required to achieve this task. My key, manifest, code etc. were all right. But, in the end after wasting a lot of time, the debug keystore which I was using was the wrong one. It's was all about the SHA1 fingerprint after all.

Categories

Resources