0

I have created a map activity. The application is running without crash but when I open the activity it shows only google logo but google map is not loaded. Therefore I checked runtime errors it shows following errors.

Error

V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = ViewRoot{615057f com.example.kularathna.gpstracker/com.example.kularathna.gpstracker.ticketBooking,ident = 4}, this = DecorView@dce7bbe[ticketBooking] E/Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. 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: AIzaSyBWfu7WllVlnzgXuNAWhU_Ca0U3EC2BDvc Android Application (;): 6B:C7:FB:B3:C6:FE:D3:22:DA:14:AE:27:B6:88:FA:13:ED:82:63:BA;com.example.kularathna.gpstracker W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4 Selected remote version of com.google.android.gms.googlecertificates, version >= 4 W/zygote64: Skipping duplicate class check due to unrecognized classloader D/Surface: Surface::disconnect(this=0x7efc6d4000,api=1) D/WindowClient: Remove from mViews: android.widget.LinearLayout{e39f9c9 V.E...... ......ID 0,0-162,75}, this = android.view.WindowManagerGlobal@7707265 Application terminated.

Following errors are showing blue color

  • W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.

  • W/zygote64: Skipping duplicate class check due to unrecognized classloader

Following errors are showing Brown color

  • E/Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. 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: AIzaSyBWfu7WllVlnzgXuNAWhU_Ca0U3EC2BDvc Android Application (;): 6B:C7:FB:B3:C6:FE:D3:22:DA:14:AE:27:B6:88:FA:13:ED:82:63:BA;com.example.kularathna.gpstracker

Xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".map">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <fragment
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:name="com.google.android.gms.maps.MapFragment"
            android:id="@+id/fragmentMap"/>
    </LinearLayout>

</RelativeLayout>

map.java file

package com.example.kularathna.gpstracker;

import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;

public class map extends AppCompatActivity implements OnMapReadyCallback {

    GoogleMap mGoogleMap;

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

        if (googleServicesAvailable()){
            Toast.makeText(this,"Perfect",Toast.LENGTH_LONG).show();
            initMap();
        }else {
//            No Google Map Layout
        }
    }

    private void initMap() {
        MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fragmentMap);
        mapFragment.getMapAsync(this);
    }

    public boolean googleServicesAvailable(){
        GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int isAvailable = api.isGooglePlayServicesAvailable(this);
        if (isAvailable == ConnectionResult.SUCCESS){
            return true;
        }else if (api.isUserResolvableError(isAvailable)){
            Dialog dialog = api.getErrorDialog(this,isAvailable,0);
            dialog.show();
        }else {
            Toast.makeText(this,"Can't connect to play services",Toast.LENGTH_LONG).show();
        }
        return false;
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mGoogleMap = googleMap;
        goToLocationZoom(39.008224,-76.8984527,15);
    }

    private void goToLocation(double longitude, double latitude) {
        LatLng latLng = new LatLng (longitude,latitude);
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng (latLng);
        mGoogleMap.moveCamera (cameraUpdate);
    }

    private void goToLocationZoom(double longitude, double latitude, float zoom) {
        LatLng latLng = new LatLng (longitude,latitude);
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
        mGoogleMap.moveCamera (cameraUpdate);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.kularathna.gpstracker">

    <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"/>

    <permission android:name="com.example.kularathna.gpstracker.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

    <uses-permission android:name="com.example.kularathna.gpstracker.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES"/>

    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".login">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".ticketBooking" />
        <activity android:name=".registration" />
        <activity android:name=".arrive" />
        <activity android:name=".home" />
        <activity android:name=".reserveSeats" />
        <activity android:name=".seatSelection" />
        <activity android:name=".map"></activity>

        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBWfu7WllVlnzgXuNAWhU_Ca0U3EC2BDvc"/>
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    </application>

</manifest>
API Key screen shot

API key screen shot

Chapa
  • 13
  • 6

2 Answers2

0

Is the SHA key registered with the api key in the google console is same as your machine's SHA key from where you generating the APK. Try to remove the restriction of SHA key from console and run the app

0

Same issue happened for me, i resolved by enabling

Maps SDK for Android

Enabled API like below image,

enter image description here

Also make sure generate API key for your application with package name like below image,

enter image description here

piet.t
  • 11,718
  • 21
  • 43
  • 52
Android
  • 1,420
  • 4
  • 13
  • 23