1

All map related APIs are on. When I try to run on a real device a blank google map screen appears. In the code below I removed api key intentionally for posting.

MainActivity.java

package com.example.hellomap;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {
    private GoogleMap mMap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        if (mMap != null) {
            return;
        }
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (mMap == null) {
            return;
        }
        // Initialize map options. For example:
        // mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- TODO: Replace "com.example.hellomap" with your desired package name -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.hellomap"
          android:versionCode="1"
          android:versionName="1.0">

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15"/>

<!-- TODO: Replace "com.example.hellomap" with your package name -->
<permission
        android:name="com.example.hellomap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.example.hellomap.permission.MAPS_RECEIVE"/>

<!-- The following four permissions -->
<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"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

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

<application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher">

    <!-- TODO: Insert your Maps API key here. See this page for more information:
         https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key -->
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="Removed for posting"/>

    <activity
            android:name="MainActivity"
            android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

main.xml (Layout)

<?xml version="1.0" encoding="utf-8"?>
<!--
See this page for more XML attribute options
https://developers.google.com/maps/documentation/android/map#using_xml_attributes
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:map="http://schemas.android.com/apk/res-auto"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          map:mapType="normal"/>
user3048641
  • 105
  • 6

4 Answers4

1

If you have updated you google-play-service library to revision 13, then you should add the following meta-data tag in your Manifest file:

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

And I suggest you recheck that you have turned on the Google Maps V2 API for Android in the API Console. Finally if all this doesn't work try to regenerate you SHA1 fingerprint and register it again in the console. Don't forget to delete your application completely from the device before testing a new API key as it is being cached.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0

Add this in your manifest file :

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

Hope this helps.

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
0

In the device, if you run the exported apk file, then you will have to change the map api key according to keystore name(keystore file is created when you export the app).

After doing this, the map will be displayed on the device.

Karan Maru
  • 991
  • 6
  • 17
0

See here,just change the api key with your key in manifest file and follow these steps: and make sure that generate api key with package name which is mentioned in android manifest file and your google_play_services_lib project should be present in your project's work space only.

Manifest file:

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

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

    <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" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.geeklabs.map.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

}

activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138