Android Google Map API V2 Blank Screen

2019-01-17 20:36发布

Hi I recently followed Vogella's tutorial on Google Map API v2. The code is similar to his. But for some reason the map shows up blank and the logcat shows no error either. I also followed this video to get the SHA1 finger print then I put the API key inside the manifest file. I used the debug keystore C:\Users\UserName.android\debug.keystore which is also the default debug keystore located in Eclipse -> Windows -> Preference -> Android -> Build.

I also generated a new API key and it still doesn't work.

Manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.barcodelibrary"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.camera.flash" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.SET_DEBUG_APP"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".HomeActivity"
            android:label="@string/title_activity_home" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity android:name=".ScanActivity"/>
        <activity android:name=".MapActivity"/>
        <activity android:name=".BarcodeHelper"/>
        <activity android:name=".JsonHelper"/>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my api key" />
    </application>

</manifest>

This is my layout file for the map activity:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity" >

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

</RelativeLayout>

This is my map activity:

public class MapActivity extends Activity { static final LatLng HAMBURG = new LatLng(53.558, 9.927); static final LatLng KIEL = new LatLng(53.551, 9.993); private GoogleMap map; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG) .title("Hamburg")); Marker kiel = map.addMarker(new MarkerOptions() .position(KIEL) .title("Kiel") .snippet("Kiel is cool") .icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_launcher))); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_map, menu); return true; } }

Thanks!

12条回答
欢心
2楼-- · 2019-01-17 21:10

Android Studio: make sure you put your key in the right hierarchy

enter image description here

查看更多
叼着烟拽天下
3楼-- · 2019-01-17 21:14

You Must Run your app in amulator having Following Configuration.... 1) Google API(x86 System image) 2) select checkBox indicating Use Host GPU..

查看更多
等我变得足够好
4楼-- · 2019-01-17 21:14

I 've got a similar problem with the map. After fixing all lib and key problems, I just saw a white sreen labled with "Google". The problem was, that I put the MapFragment into a ScrollView. After removing the ScrollView everything works fine. I can see the map.

查看更多
地球回转人心会变
5楼-- · 2019-01-17 21:16

In my case it was an existing app that I cloned from GitHub and did not change the API Key. What worked for me is to enable the SHA-1 of my signing certificate. Follow these short instructions to get a SHA-1 fingerprint.

Then I had the main developer add my SHA-1 fingerprint to the authorized packages for his relevant API Key here. Then I did the build again in the same way and it worked.

查看更多
你好瞎i
6楼-- · 2019-01-17 21:23

For me it turned out that I didn't enabled the Google Maps Android API v2. We were using another Google Maps API which I assumed to be the same.

查看更多
疯言疯语
7楼-- · 2019-01-17 21:23

if it didn't work though,follow this

Solving the blank screen issue on maps: Hi there ,i have been through this blank screen for a very long time and tried out all solutions u can imagine.Now it solved and the steps were:

1-Go through all steps of this tutorial carefully.

2-If the blank screen still the same ,delete you debug key store file that exists in c:\Users\youUser.android\debug.keystore <-- delete this file

3-On the eClips IDE rebuild your app so it will automatically re create this file. 4-On eclips go to Window-->preferences-->android-->Build copy the fresh generated SHA1 and then follow the normal key generation steps . 5-Run on your real device ,and i hope you'll see your map :)

查看更多
登录 后发表回答