Google Map Signed API Key Errors in Android

Google map signed api key errors in Android

I had the same problem and I figured there wasn't any helpful answer around on the internet so hoping this should help everyone in the future.

When using GoogleMaps for Android, you need two keys - debug and release.

The "debug" key is kind of a misleading term. This key is also to be used when you develop the app in Eclipse. So essentially, use the debug key for development, testing, debugging.

When you're ready to launch the app to Market, set the android:debuggable="false" in the AndroidManifest.xml and use the Signed API key.

When using the signed API key, the MapView will show up ONLY when the app is installed from the Android Market. So, installing the app from Eclipse (Run As, Debug As, etc) or command line (adb install) won't show the MapView. Rest assured, once the app is in the Market - you download it and the MapView will show up.

With the signed API key, if you deploy the app from Eclise, you will get a "Server returned 3, IOProcessing Exception 26" as a warning - just ignore it.

Note: Also ensure there are no duplicate instances of the same MapView. If your app needs "x" no. of MapViews, generate "x" no. of new signed keys (one for each MapView) since GoogleMaps has a query limit for a single MapView instance.

For getting both the keys, follow the steps for Obtaining API keys for GoogleMaps on Android.

Happy Coding!

UPDATE:

The link above for obtaining api keys is now a deprecated procedure. Refer Obtaining API keys for GoogleMaps Android API v2 going forward.

Google Maps API Key Error when launching Activity

You have to initialize your map in onCreate() as done here and this will do your job.

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback
{

private GoogleMap mMap;

@Override
public void onMapReady(GoogleMap googleMap)
{
Toast.makeText(this, "Map is Ready", Toast.LENGTH_SHORT).show();
Log.d("Mapready", "onMapReady: map is ready");
mMap = googleMap;

if (mLocationPermissionsGranted)
{
getDeviceLocation();

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);

}
}

private static final String TAG = "MapsActivity";

private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
private static final float DEFAULT_ZOOM = 15f;

//vars
private Boolean mLocationPermissionsGranted = false;
private FusedLocationProviderClient mFusedLocationProviderClient;



@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

initMap();

getLocationPermission();
}

private void getDeviceLocation(){
Log.d(TAG, "getDeviceLocation: getting the devices current location");

mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);

try{
if(mLocationPermissionsGranted){

final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()){
Log.d(TAG, "onComplete: found location!");
Location currentLocation = (Location) task.getResult();

moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
DEFAULT_ZOOM);

}else{
Log.d(TAG, "onComplete: current location is null");
Toast.makeText(MapsActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage() );
}
}

private void moveCamera(LatLng latLng, float zoom){
Log.d(TAG, "moveCamera: moving the camera to: lat: " + latLng.latitude + ", lng: " + latLng.longitude );
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
}

private void initMap(){
Log.d(TAG, "initMap: initializing map");
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

mapFragment.getMapAsync(MapsActivity.this);
}

private void getLocationPermission(){
Log.d(TAG, "getLocationPermission: getting location permissions");
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION};

if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED){
mLocationPermissionsGranted = true;
initMap();
}else{
ActivityCompat.requestPermissions(this,
permissions,
LOCATION_PERMISSION_REQUEST_CODE);
}
}else{
ActivityCompat.requestPermissions(this,
permissions,
LOCATION_PERMISSION_REQUEST_CODE);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
Log.d(TAG, "onRequestPermissionsResult: called.");
mLocationPermissionsGranted = false;

switch(requestCode){
case LOCATION_PERMISSION_REQUEST_CODE:{
if(grantResults.length > 0){
for(int i = 0; i < grantResults.length; i++){
if(grantResults[i] != PackageManager.PERMISSION_GRANTED){
mLocationPermissionsGranted = false;
Log.d(TAG, "onRequestPermissionsResult: permission failed");
return;
}
}
Log.d(TAG, "onRequestPermissionsResult: permission granted");
mLocationPermissionsGranted = true;
//initialize our map
initMap();
}
}
}
}

}

Also, do the following changes in the manifest file:-

<meta-data android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>

Google Maps Android API Authorization failure, despite SHA1 keys registered

Check whether you have copy pasted your API key in google_maps_api.xml in values folder. From the error log(i'm assuming), your API key is shown as "YOUR_KEY_HERE", that's exactly the default value in the file. Please check.

UPDATE

IMG

Open the google_maps_api.xml and paste your api key at "YOUR_KEY_HERE". That will do it.

Google Maps API Key in release build doesn't work

I had this same problem, it was super frustrating. What I ended up doing was taking the key I made using my release keystore and putting it in the google developers console. Then, added the following into the android manifest.

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="KEY GOES HERE"/>

I'm sure you read the documentation on this, but make sure you follow the instructions for the release certificate to the dot.

https://developers.google.com/maps/documentation/android/signup

You could also follow the link that was generated for you in the google_maps_api.xml file. This automates the process of entering the key into the developer console. However, make sure you still add that meta data value into your manifest.

Ensure that the Google Maps Android API v2 is enabled. I am getting this error when I try to Implement Google Maps

From error it is clear that You did not enable google map api for android. To enable,

  1. Login google developer console
  2. Select Library option from left side panel.
  3. Now you can see all API list and go to Google Maps APIs and select
    Google Maps Android API .
  4. Now you can see option to enable/disable API. Enable it.

I hope it help you.

Google Maps are not showing up in a signed apk

It sounds like you only have the API key entered in the debug google_maps_api.xml. Also, it sounds like you're using the same API key for debug and release, but you still need to enter it in the google_maps_api.xml under the release folder as well as the one in the debug folder.

It's a little confusing, because when the project is in Android view, you can only see the debug file (although it should have (debug) in parenthesis next to it in that view).

In order to modify the release version, switch to Project view by using the dropdown in the upper left of the Project Explorer. Then, expand app/src/, and you will see subfolders debug and release. Under there, you should see two separate google_maps_api.xml files under debug/res/values and release/res/values.

Make sure that the API key is populated in the google_maps_api.xml file under the release/res/values folder, since this is the one that will be used for the signed release apk.

Sample Image



Related Topics



Leave a reply



Submit