Google maps not showing Android

14,007

Solution 1

Even after you follow steps from Official documentation or you're done with steps from Android Studio, and you're still not able to see the map, follow these steps to ensure whether it is a problem with API key or not:

  1. Filter with 'Google Maps' in your logcat.
  2. You will see an error message, which contains the correct package name & SHA key which should be present as it is in the API Key
  3. Go to Google Cloud Console -> API -> Credentails, and cross-verify both the above, correct if necessary.
  4. Wait for 10-15 minutes for the API Key changes to be reflected

Solution 2

In addition to other posts, you may refer with this thread. The reason may be the API key used was created with the wrong keystore. You need to make sure you use your debug keystore when you create an API key in the Google API console. Based from this link, 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. 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.

Solution 3

To work with Google Maps you must:

  1. Add logic to the Fragment or Activity.
  2. Add the map fragment element to the layer.
  3. Obtain an API Key (you probably need to associate the key to your debug version and your signed version of the app, everyone will have a different signature but both can share the same key).
  4. Configure the application manifest. Here, to use Google Maps you will need: Internet Access, Open GL specifications, if the map will be stored locally you sill need access to the device storage too, as the map libraries are included as part of the google play services you need to configure this too.

At the manifest level:

<!-- Location if you will use this -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<uses-permission android:name="com.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

At the application level inside the manifest:

    <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="<YOUR MAP API KEY>" />

Solution 4

make sure you have added the map key in the release folder (app>src>release>res>values>google_map_api.xml) too.

Share:
14,007
kevinh1998
Author by

kevinh1998

Software engineer student at Univeristy of Amsterdam. Currently busy developing iOS Apps.

Updated on June 18, 2022

Comments

  • kevinh1998
    kevinh1998 almost 2 years

    I want to implement google maps in my app. I added a google maps activity and created a key. I didn't change anything in the code elsewhere. I should work but it doesn't.

    MapsActivity

    public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
    
    private GoogleMap mMap;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }
    
    
    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
    
        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
    

    }

    activity_maps.xml

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.kevin.map.MapsActivity" />