1

I am working on google maps in my application. Now in android the map is not being displayed although I have checked the code it's fine and everything is working.

The steps I have checked and they are working fine: 1) the SHA code is fine. 2) The key I inserted in application is fine. 3) I have enabled the map API for my application.

But the logcat displays the following when I access the map fragment:

06-22 18:57:47.380 8417-10561/ I/b: Sending API token request.
06-22 18:57:50.300 8417-10561/ E/b: Authentication failed on the server.
06-22 18:57:50.300 8417-10561/ 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.

06-22 18:57:50.300 8417-10561/ 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: AIz------------------------------------S
          Android Application (<cert_fingerprint>;<package_name>): SHA-1FingerPrint;PackageName

Now I have searched through internet regarding this issue and I haven't found a solution yet. I have gone through the following questions but no result.

Google Maps V2 not working in production with correct key

Google Maps Android API v2 Authorization failure

This is my activity code for the map:

private void setupWebView(View parentView) {
    loading = (ProgressBar) parentView.findViewById(R.id.loading);
    loading.setVisibility(View.GONE);
    if (googleMap == null) {
        googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.mapf)).getMap();

    }
    setupMarkers(searchCenters.getText().toString());
}

private void setupMarkers(String searchFor) {
    googleMap.clear();
    if (searchFor == null || searchFor == "") {
        for (Center center : centers) {
            markers.add(
                    googleMap
                            .addMarker(new MarkerOptions()
                                    .position(new LatLng(center.getAddress().getLatitude(),
                                            center.getAddress().getLongitude()))
                                    .title(center.getName()).visible(true)));

        }
    } else {
        for (Center center : centers) {
            if (center.getName().toLowerCase().contains(searchFor.toLowerCase())) {
                markers.add(
                        googleMap.addMarker(new MarkerOptions()
                                .position(new LatLng(center.getAddress().getLatitude(),
                                        center.getAddress().getLongitude()))
                                .title(center.getName()).visible(true)));
            } else {
                markers.add(
                        googleMap.addMarker(new MarkerOptions()
                                .position(new LatLng(center.getAddress().getLatitude(),
                                        center.getAddress().getLongitude()))
                                .title(center.getName()).visible(false)));
            }
        }
    }

And the result is like this:

enter image description here

Can anybody help me with this issue. I know this has been asked many time here but still I can't find the answer.

Umair
  • 5,756
  • 15
  • 39
  • 47
  • 1
    At last I found the solution . may beit will helps you http://stackoverflow.com/questions/16551458/android-google-maps-not-displaying/43776686#43776686 – mehmet May 04 '17 at 07:49
  • @mehmet thank you for your comment. But I resolved this issue by re-entering the credentials and deleting the key and inserting it again and it worked fine. I never understood though why and how it happened – Umair May 04 '17 at 08:31

2 Answers2

2

Android Studio has two path for

app/src/debug/res/values/google_maps_api.xml
app/src/release/res/values/google_maps_api.xml

make sure that both has the same google_maps_key

kulakesh
  • 166
  • 1
  • 6
1

Based from the error logs you provide, Google Maps Android API: Authorization failure. make sure to activite the Google Maps Android API v2 service in the Google API's console, use correct package name while generating API Key, make Sure you are using the correct keystore file for generating the SHA1 and as suggested in the logs, ensure that the Google Maps Android API v2 is enabled, ensure that the following Android key exists.

What I can advice is to read through the Official Google Documentation for Maps Android API, the guide is a quick start to add map to an Android app. The documents also discuss how to get Maps API Key and also include sample code.

Here's a sample code which includes a number of samples illustrating the use of the Google Maps Android API: https://github.com/googlemaps/android-samples

Android Enthusiast
  • 4,447
  • 2
  • 11
  • 27
  • Thanks for your answer. Actually I was providing everything correctly. When I re-entered the credentials after deleting the key, it started to work correctly. don't know how and why. – Umair Jul 03 '16 at 15:03
  • Hello umair, if you found any solution how it works, please post it here. by that way, we can help other who encounter this issue. – Android Enthusiast Nov 21 '17 at 20:13
  • actually this was kind of a wired problem. Everything was working fine. I just deleted the key and re-entered it and it started to work fine. Didn't changed anything other then key. – Umair Nov 22 '17 at 04:45