I have developed an android app for my company, where I have introduced a map in a fragment.
The app works fine on my phone, but when providing this app to other fellow workers, in their phones the map is not showing, it appears the focus buttons and the Google logo, but that's it, no map.
layout
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
class="com.google.android.gms.maps.SupportMapFragment"/>
manifest
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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"/>
<!-- 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"/>
...
<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="AIzaSyArrfA3PQ9kVcwucUGZCoc9yMUC9wc2g_4"/>
Fragment
/*Try to obtain the map from the SupportMapFragment*/
mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
it's a debug key problem.
you must use a release key.
With version 2 API's you can use the same key for release and debug. In your google api's console edit your allowed android apps and on each line put your debug/release key, and then your app name. You can use multiple lines, then it will work with both keys.
In Google Developer API Console
Click on Create New Android key...
In cmd.exe/Terminal: keytool -list -v -keystore mystore.keystore
Password: android
Now enter SHA1 key;package name for debug and press enter
Enter SHA1 key;package name for release
Click on Create
Now use this API key your project
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/common_map_api_key"/>
Related
I have read all the similar questions and did everything that was described in them, but did not help.
Google Maps API v2 is Enabled and
API key is correct
I just chose GoogleMapsActivity in "New project", then created a key.jks, created sha1 by keytool, created public api access key, put my API key in manifest.
I tried:
clean-rebuild-unistall app-install
updated api key many times
create a new project with the new key.jks (and all over again)
delete and create api key
Here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dandewine.user.thinkmobiletest" >
<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 ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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="AIza**************************" />
<activity
android:name=".ActivityMain"
android:label="#string/title_activity_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is my activity:
public class ActivityMain extends FragmentActivity implements OnMapReadyCallback {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);
SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
}
Logcat:
E/Google Maps Android API﹕ Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
07-27 14:52:37.551 25002-25035/com.dandewine.user.thinkmobiletest E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIza****************************
Android Application (<cert_fingerprint>;<package_name>): 8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:74:97:18:57:88;com.dandewine.user.thinkmobiletest
UPDATE: I have different SHA1 fingerprints in google dev. console and in logs, how to deal with that?
Can anyone help with advice.
It sounds like you're using the SHA1 fingerprint from the keystore that you will be using to generate a signed apk.
For debugging/running from Android Studio, you need to use the SHA1 fingerprint that Android Studio uses to sign the apk.
Note that you can get this SHA1 fingerprint by using command line:
For Mac or Linux:
keytool -list -v -keystore ~/.android/debug.keystore
For Windows:
keytool -list -v -keystore C:\User\YourUser\.android\debug.keystore
with password "android".
However, since you already have the correct value in your logs,
just copy this from your logs (I modified it here, don't copy from here):
8C:2B:4C:F7:CF:FB:EC:D5:DC:D7:D0:5D:6E:30:49:xx:xx:xx:xx:xx;com.dandewine.user.thinkmobiletest
And paste that into your API Key in the developer console.
You can add multiple fingerprint/package values to each API key, one per line (you can also see that in the instructions when you are editing an API key).
You can also configure a different API key for debug and release, if you do that take a look at this answer.
add the following in manifest:
<permission
android:name="com.dandewine.user.thinkmobiletest.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.tp.lib.tp.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
also:
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
Check if you have included your signature key in debug and release mode, read this: http://developer.android.com/tools/publishing/app-signing.html#cert
I'm trying to load a map with Google API V2, but i meet few errors that i don't understand..
I've these errors :
Could not find class 'gpr', referenced from method gps.a
Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence', referenced from method glt.a
Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Here, it's my manifest (a part) :
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/keyAndroid"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I forgot something ? I checked the SHA1 of my certificate, and there is no error with that.
Thx,
There is a difference between Debug and Release keys. You need to generate the specific SHA1 key for the developer console and for your specific use of the app.
DEBUG
When you want to see the map in debug, you will find the debug key here (eclipse)
Or in the folder
~/.android/debug.keystore
In Windows it is
C:\User\YourUser.android\debug.keystore
You need to generate the SHA1 key of that keystore and add it in the Developer Console in your Google Maps API v2 for Android
RELEASE
For release keys you will have to go trough these four steps:
You need to (taken from here Generating Google map Release API Key):
Create your own signing key that you will use for publishing, using Keytool : http://developer.android.com/guide/publishing/app-signing.html#cert
Get the MD5 fingerprint of your newly generated key : https://developers.google.com/maps/documentation/android/mapkey#getfingerprint
Submit the signature to this link to get your Google Maps key : https://developers.google.com/android/maps-api-signup?hl=fr
Export your application with your newly created key, in Eclipse : right click on your projet -> Android Tools -> Export signed application package.
Important thing to notice here, that you need to add the package name at the end of the SHA1 key. Like
AB:CD:EF...:08;com.yourpackage.yourapp
USING THE KEYS
Then when you got those two keys, you will have to update it always when you are either using debug or release. Don't mix them up, write a comment next to the key entry like
<!-- DEBUG KEY: 12345... -->
<!-- RELEASE KEY: 23456... ->
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
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
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.