0

I followed this tutorial: How can I create an Android application in Android Studio that uses the Google Maps Api v2?

And I compiled and get sample maps application running on my device. The only problem is that maps dont display in my application, all I got is blank screen.

My AndroidManifest.xml (all i changed is apikey)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.mapdemo"
  android:versionCode="3"
  android:versionName="2.2.1">
  <permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
    <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
    <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- My Location -->
    <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"/>
    <!-- End of copy. -->
    <application
android:icon="@drawable/ic_launcher"
android:label="@string/demo_title"
android:hardwareAccelerated="true">
<!-- ** You need to replace the key below with your own key. **
     The example key below will not be accepted because it is not linked to the
     certificate which you will use to sign this application.
     See: https://developers.google.com/maps/documentation/android/start
     for instructions on how to get your own key. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="MyOwnGeneratedKey"/>
<activity android:name=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
  </intent-filter>
</activity>
<activity
  android:name=".BasicMapActivity"
  android:label="@string/basic_map"/>
<activity
  android:name=".CameraDemoActivity"
  android:label="@string/camera_demo"/>
<activity
  android:name=".CircleDemoActivity"
  android:label="@string/circle_demo"/>
<activity
  android:name=".EventsDemoActivity"
  android:label="@string/events_demo"/>
<activity
  android:name=".GroundOverlayDemoActivity"
  android:label="@string/groundoverlay_demo"/>
<activity
  android:name=".LayersDemoActivity"
  android:label="@string/layers_demo"/>
<activity
  android:name=".LegalInfoActivity"
  android:label="@string/legal_info"/>
<activity
  android:name=".LocationSourceDemoActivity"
  android:label="@string/locationsource_demo"/>
<activity
  android:name=".MarkerDemoActivity"
  android:label="@string/marker_demo"/>
<activity
  android:name=".MultiMapDemoActivity"
  android:label="@string/multi_map_demo"/>
<activity
  android:name=".MyLocationDemoActivity"
  android:label="@string/my_location_demo"/>
<activity
  android:name=".OptionsDemoActivity"
  android:label="@string/options_demo"/>
<activity
  android:name=".PolygonDemoActivity"
  android:label="@string/polygon_demo"/>
<activity
  android:name=".PolylineDemoActivity"
  android:label="@string/polyline_demo"/>
<activity
  android:name=".ProgrammaticDemoActivity"
  android:label="@string/programmatic_demo"/>
<activity
  android:name=".RawMapViewDemoActivity"
  android:label="@string/raw_mapview_demo"/>
<activity
  android:name=".RetainMapActivity"
  android:label="@string/retain_map"/>
<activity
  android:name=".SaveStateDemoActivity"
  android:label="@string/save_state_demo"/>
<activity
  android:name=".TileOverlayDemoActivity"
  android:label="@string/tile_overlay_demo"/>
<activity
  android:name=".UiSettingsDemoActivity"
  android:label="@string/uisettings_demo"/>
  </application>
</manifest>

I created key in console using my debug fingerprint, it looks like this:

A1:FE:B5:E2:5E:0E:1A:8E:CC:8F:07:CC:4D:D0:95:13:0B:E7:1B:EC;com.example.mapdemo

Logcat for maps:

08-03 02:41:14.330  13942-14784/com.example.mapdemo I/Google Maps Android API: Failed to            contact Google servers. Another attempt will be made when connectivity is established.
08-03 02:41:29.840  13942-14812/com.example.mapdemo E/Google Maps Android API: Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Community
  • 1
  • 1
pawel
  • 5,976
  • 15
  • 46
  • 68
  • [check this post](http://stackoverflow.com/questions/17679317/android-google-maps-v2-authentication-error/17684309#17684309) , if it is the case. – tony m Aug 03 '13 at 04:49
  • you have to use a Release key, not a debug key. – svlzx Dec 13 '13 at 12:02

2 Answers2

1
    <meta-data android:name="com.google.android.maps.v2.API_KEY"
    android:value="MyOwnGeneratedKey"/>

You need to use Google API console to generate your own key using

    A1:FE:B5:E2:5E:0E:1A:8E:CC:8F:07:CC:4D:D0:95:13:0B:E7:1B:EC;com.example.mapdemo

and then substitute it in the manifest. The format should be something similar to

    AIzaSyB-sKpf4b9kSM6DX40WyjExC7VTRabAvcw

Also, you need to flick the switch on the Google Map API v2 in the services page in the API console.

wakaka
  • 533
  • 1
  • 7
  • 21
  • I did it ;) i have my own key in manifest, I typed the MyOwnGeneratedKay just for purpose of posting here :) – pawel Aug 03 '13 at 01:46
0

Update your Google Play Services by Android SDK Manager and then use it by importing it in eclipse as it has the new updates and then add these lines to your manifest file within the element which are missing from your maifest-

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

Uninstall the app from the device and install the fresh version.

amit singh
  • 1,407
  • 2
  • 16
  • 25