【问题标题】:Android Map is not showing even on the phone only white screen is seen即使在手机上也没有显示 Android 地图,只看到白屏
【发布时间】:2014-02-20 07:16:30
【问题描述】:

我的项目有一个地图活动,以及使用意图链接的其他活动。然而,所有其他活动都被看到了;地图仅在手机上显示空白屏幕,并在模拟器上显示错误“更新谷歌播放服务”。请帮忙

ActivityMap.java

package com.example.bloodbankmap;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class ActivityMap extends FragmentActivity {

    // Google Map
    private GoogleMap googleMap;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);

        try {
            // Loading map
            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * function to load map. If map is not created it will create it for you
     * */
    private void initilizeMap() {
        if (googleMap == null) {
           // googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    //R.id.map)).getMap();
            googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

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

}

map.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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



 <!--   <Button
        android:id="@+id/button10"
        android:layout_width="105dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="View Complete Stock " /> -->

</RelativeLayout>

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bloodbankmap"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="com.example.bloodbankmap.permission.MAPS_RECEIVE" />

    <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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <!-- Requires OpenGL ES version 2 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/blood"
        android:label="@string/app_name">
        <activity
            android:name="com.example.bloodbankmap.Launcher"
            android:label="@string/app_name"
            android:theme="@style/AppBaseTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.bloodbankmap.List"
            android:label="@string/app_name" >


        </activity>
         <activity
            android:name="com.example.bloodbankmap.ActivityMap"
            android:label="@string/app_name" >
          </activity> 

     <activity
            android:name="com.example.bloodbankmap.Registration"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.Area"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.Disp_bb"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.Nearest_BB"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.Notifications"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.Notify"
            android:label="@string/app_name" >
        </activity>

   <activity
            android:name="com.example.bloodbankmap.SByBlgrp"
            android:label="@string/app_name" >
        </activity>


        <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyD-0S4belIQQUFoYL26Y_fimoS6FZ4udpE" />
        <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    </application>

</manifest>

我的日志猫

02-20 06:07:15.317: D/dalvikvm(1022): GC_CONCURRENT freed 272K, 15% free 2489K/2904K, paused 17ms+3ms, total 62ms
02-20 06:07:15.317: D/dalvikvm(1022): WAIT_FOR_CONCURRENT_GC blocked 46ms
02-20 06:07:15.327: I/dalvikvm-heap(1022): Grow heap (frag case) to 3.254MB for 721184-byte allocation
02-20 06:07:15.377: D/dalvikvm(1022): GC_FOR_ALLOC freed 1K, 12% free 3191K/3612K, paused 48ms, total 49ms
02-20 06:07:15.557: I/Choreographer(1022): Skipped 44 frames!  The application may be doing too much work on its main thread.
02-20 06:07:15.597: D/gralloc_goldfish(1022): Emulator without GPU emulation detected.
02-20 06:07:52.841: D/dalvikvm(1161): GC_FOR_ALLOC freed 251K, 14% free 2489K/2884K, paused 36ms, total 38ms
02-20 06:07:52.841: I/dalvikvm-heap(1161): Grow heap (frag case) to 3.253MB for 721184-byte allocation
02-20 06:07:52.901: D/dalvikvm(1161): GC_FOR_ALLOC freed 2K, 12% free 3191K/3592K, paused 49ms, total 49ms
02-20 06:07:52.961: D/dalvikvm(1161): GC_CONCURRENT freed <1K, 12% free 3191K/3592K, paused 5ms+25ms, total 65ms
02-20 06:07:53.101: I/Choreographer(1161): Skipped 33 frames!  The application may be doing too much work on its main thread.
02-20 06:07:53.151: D/gralloc_goldfish(1161): Emulator without GPU emulation detected.
02-20 06:07:55.442: I/Choreographer(1161): Skipped 57 frames!  The application may be doing too much work on its main thread.
02-20 06:07:55.811: I/Choreographer(1161): Skipped 399 frames!  The application may be doing too much work on its main thread.
02-20 06:07:55.841: D/dalvikvm(1161): GC_CONCURRENT freed 731K, 24% free 2858K/3732K, paused 6ms+43ms, total 163ms
02-20 06:07:57.901: I/Choreographer(1161): Skipped 2434 frames!  The application may be doing too much work on its main thread.
02-20 06:07:58.231: I/Choreographer(1161): Skipped 70 frames!  The application may be doing too much work on its main thread.
02-20 06:07:58.392: I/Choreographer(1161): Skipped 175 frames!  The application may be doing too much work on its main thread.
02-20 06:07:58.571: I/Choreographer(1161): Skipped 42 frames!  The application may be doing too much work on its main thread.
02-20 06:07:59.131: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.181: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.241: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.281: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.321: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.351: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.391: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.422: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.461: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.651: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.681: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.781: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.821: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.902: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:07:59.961: W/GooglePlayServicesUtil(1161): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:08:00.021: D/dalvikvm(1161): GC_CONCURRENT freed 317K, 20% free 2993K/3732K, paused 15ms+58ms, total 255ms
02-20 06:08:00.081: I/Choreographer(1161): Skipped 157 frames!  The application may be doing too much work on its main thread.
02-20 06:08:00.351: I/Choreographer(1161): Skipped 128 frames!  The application may be doing too much work on its main thread.
02-20 06:08:00.641: I/Choreographer(1161): Skipped 30 frames!  The application may be doing too much work on its main thread.
02-20 06:56:51.331: E/Trace(1652): error opening trace file: No such file or directory (2)
02-20 06:56:51.991: D/dalvikvm(1652): GC_FOR_ALLOC freed 262K, 14% free 2489K/2892K, paused 87ms, total 89ms
02-20 06:56:52.001: I/dalvikvm-heap(1652): Grow heap (frag case) to 3.253MB for 721184-byte allocation
02-20 06:56:52.061: D/dalvikvm(1652): GC_FOR_ALLOC freed 2K, 12% free 3191K/3600K, paused 54ms, total 54ms
02-20 06:56:52.131: D/dalvikvm(1652): GC_CONCURRENT freed <1K, 12% free 3191K/3600K, paused 5ms+4ms, total 71ms
02-20 06:56:52.301: I/Choreographer(1652): Skipped 38 frames!  The application may be doing too much work on its main thread.
02-20 06:56:52.331: D/gralloc_goldfish(1652): Emulator without GPU emulation detected.
02-20 06:56:54.451: I/Choreographer(1652): Skipped 43 frames!  The application may be doing too much work on its main thread.
02-20 06:56:54.801: I/Choreographer(1652): Skipped 382 frames!  The application may be doing too much work on its main thread.
02-20 06:56:54.821: D/dalvikvm(1652): GC_CONCURRENT freed 731K, 24% free 2858K/3732K, paused 5ms+22ms, total 146ms
02-20 06:56:55.001: I/Choreographer(1652): Skipped 44 frames!  The application may be doing too much work on its main thread.
02-20 06:56:55.651: I/Choreographer(1652): Skipped 45 frames!  The application may be doing too much work on its main thread.
02-20 06:56:56.032: I/Choreographer(1652): Skipped 99 frames!  The application may be doing too much work on its main thread.
02-20 06:57:03.691: I/Choreographer(1652): Skipped 105 frames!  The application may be doing too much work on its main thread.
02-20 06:57:04.301: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.351: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.411: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.441: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.491: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.531: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.581: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.611: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.651: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.881: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:04.931: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:05.082: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:05.131: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:05.231: D/dalvikvm(1652): GC_CONCURRENT freed 292K, 20% free 2987K/3732K, paused 6ms+38ms, total 256ms
02-20 06:57:05.241: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:05.291: W/GooglePlayServicesUtil(1652): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 06:57:05.371: I/Choreographer(1652): Skipped 71 frames!  The application may be doing too much work on its main thread.
02-20 06:57:05.681: I/Choreographer(1652): Skipped 114 frames!  The application may be doing too much work on its main thread.
02-20 06:57:07.101: I/Choreographer(1652): Skipped 70 frames!  The application may be doing too much work on its main thread.
02-20 06:57:07.271: I/Choreographer(1652): Skipped 45 frames!  The application may be doing too much work on its main thread.
02-20 06:57:14.221: I/Choreographer(1652): Skipped 55 frames!  The application may be doing too much work on its main thread.
02-20 06:57:14.971: I/Choreographer(1652): Skipped 51 frames!  The application may be doing too much work on its main thread.
02-20 06:57:15.516: I/Choreographer(1652): Skipped 87 frames!  The application may be doing too much work on its main thread.
02-20 06:57:16.541: I/Choreographer(1652): Skipped 30 frames!  The application may be doing too much work on its main thread.
02-20 06:57:17.311: I/Choreographer(1652): Skipped 48 frames!  The application may be doing too much work on its main thread.
02-20 07:35:21.421: D/dalvikvm(1811): GC_CONCURRENT freed 281K, 15% free 2491K/2916K, paused 17ms+6ms, total 105ms
02-20 07:35:21.421: D/dalvikvm(1811): WAIT_FOR_CONCURRENT_GC blocked 33ms
02-20 07:35:21.442: I/dalvikvm-heap(1811): Grow heap (frag case) to 3.256MB for 721184-byte allocation
02-20 07:35:21.492: D/dalvikvm(1811): GC_FOR_ALLOC freed 4K, 12% free 3191K/3624K, paused 46ms, total 46ms
02-20 07:35:21.751: I/Choreographer(1811): Skipped 43 frames!  The application may be doing too much work on its main thread.
02-20 07:35:21.781: D/gralloc_goldfish(1811): Emulator without GPU emulation detected.
02-20 07:35:23.801: I/Choreographer(1811): Skipped 61 frames!  The application may be doing too much work on its main thread.
02-20 07:35:24.181: D/dalvikvm(1811): GC_CONCURRENT freed 731K, 24% free 2854K/3728K, paused 6ms+70ms, total 146ms
02-20 07:35:24.201: I/Choreographer(1811): Skipped 462 frames!  The application may be doing too much work on its main thread.
02-20 07:35:24.391: I/Choreographer(1811): Skipped 36 frames!  The application may be doing too much work on its main thread.
02-20 07:35:24.941: I/Choreographer(1811): Skipped 35 frames!  The application may be doing too much work on its main thread.
02-20 07:35:25.351: I/Choreographer(1811): Skipped 101 frames!  The application may be doing too much work on its main thread.
02-20 07:35:25.982: I/Choreographer(1811): Skipped 62 frames!  The application may be doing too much work on its main thread.
02-20 07:35:26.501: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.551: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.581: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.631: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.671: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.711: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.751: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.781: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.821: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:26.981: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.001: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.241: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.281: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.361: D/dalvikvm(1811): GC_CONCURRENT freed 276K, 20% free 3003K/3728K, paused 69ms+48ms, total 281ms
02-20 07:35:27.372: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.411: W/GooglePlayServicesUtil(1811): Google Play services out of date.  Requires 4242000 but found 3136130
02-20 07:35:27.502: I/Choreographer(1811): Skipped 87 frames!  The application may be doing too much work on its main thread.
02-20 07:35:27.771: I/Choreographer(1811): Skipped 99 frames!  The application may be doing too much work on its main thread.
02-20 07:35:29.351: I/Choreographer(1811): Skipped 30 frames!  The application may be doing too much work on its main thread.
02-20 07:35:30.241: D/AndroidRuntime(1811): Shutting down VM
02-20 07:35:30.251: W/dalvikvm(1811): threadid=1: thread exiting with uncaught exception (group=0x40a71930)

02-20 07:35:30.271: E/AndroidRuntime(1811): FATAL EXCEPTION: main
02-20 07:35:30.271: E/AndroidRuntime(1811): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.gms flg=0x80000 pkg=com.android.vending }
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Activity.startActivityForResult(Activity.java:3370)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Activity.startActivityForResult(Activity.java:3331)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Activity.startActivity(Activity.java:3566)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.Activity.startActivity(Activity.java:3534)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at com.google.android.gms.dynamic.a$5.onClick(Unknown Source)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.view.View.performClick(View.java:4204)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.view.View$PerformClick.run(View.java:17355)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.os.Handler.handleCallback(Handler.java:725)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.os.Looper.loop(Looper.java:137)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at android.app.ActivityThread.main(ActivityThread.java:5041)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at java.lang.reflect.Method.invoke(Method.java:511)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 07:35:30.271: E/AndroidRuntime(1811):     at dalvik.system.NativeStart.main(Native Method)
02-20 07:35:33.941: D/dalvikvm(1825): GC_CONCURRENT freed 250K, 14% free 2589K/2984K, paused 74ms+4ms, total 156ms
02-20 07:35:34.101: I/Choreographer(1825): Skipped 127 frames!  The application may be doing too much work on its main thread.
02-20 07:35:34.111: D/gralloc_goldfish(1825): Emulator without GPU emulation detected.
02-20 07:35:34.373: I/Choreographer(1825): Skipped 213 frames!  The application may be doing too much work on its main thread.
02-20 07:35:35.283: I/Choreographer(1825): Skipped 88 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.031: I/Choreographer(1825): Skipped 92 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.081: I/Choreographer(1825): Skipped 43 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.191: I/Choreographer(1825): Skipped 32 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.281: I/Choreographer(1825): Skipped 36 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.684: I/Choreographer(1825): Skipped 88 frames!  The application may be doing too much work on its main thread.
02-20 07:35:36.831: I/Choreographer(1825): Skipped 98 frames!  The application may be doing too much work on its main thread.

【问题讨论】:

  • 是您的 apikey 权利。尝试生成一个新的
  • 进入 SDK 管理器并更新 Google Play 服务,发布了新的更新
  • 我的 google play 服务已经更新
  • 请试用真机
  • o 它甚至无法在手机上运行;它只显示一个空白的白屏;但是它显示正在搜索 gps

标签: android google-maps android-layout android-maps-v2


【解决方案1】:

您的 api 密钥是使用 SHA1 指纹生成的,该指纹不是从您的计算机生成的,即正在发生指纹不匹配。 或者您提供了错误的 api 密钥。

同时在 sdk 中更新您的 Google Play 服务。

【讨论】:

  • 我已经从我自己的计算机上创建了一个正确的 sha1 指纹,并将 google play 服务更新到了最新的
  • 在 Android Api Console 中,您是否打开了 Map APi V2 切换按钮?
  • 是的,API V2 按钮已打开
【解决方案2】:

你不能在模拟器上模拟谷歌地图你只需要一个真正的设备来处理地图,因为 adt 模拟器没有安装谷歌播放服务,只要确保谷歌服务更新你的 api 密钥没有错并去测试您在真实设备上的应用程序,但是这必须知道我搜索并找到了这个Link 去看看他们描述了您如何在模拟器中运行 Google 地图。

我已经更新了我的答案并显示我的代码与你的有点不同,但它可能对你有帮助

public class MainActivity extends FragmentActivity {

private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
MapView mMapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
        setContentView(R.layout.activity_mapview);

        // 1- get reference to MapView
        mMapView = (MapView)findViewById(R.id.map);
        // 2- MapView has the same life cycles as the Activity 
        mMapView.onCreate(savedInstanceState);


    }else {
        setContentView(R.layout.activity_main);
    }

}

@Override
protected void onDestroy() {
    super.onDestroy();
    mMapView.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    mMapView.onPause();
}

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

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mMapView.onSaveInstanceState(outState);
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mMapView.onLowMemory();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/**
 * Test and check if Google Play Services is available 
 * @return boolean
 */
public boolean servicesOK() {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();
    }
    else {
        Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
    }
    return false;
}

}

activity_mapview.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Adds a mapView to the layout -->
<com.google.android.gms.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</com.google.android.gms.maps.MapView>

manifest.xml

<?xml version="1.0" encoding="utf-8"?>

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

<uses-permission android:name="com.example.gmapsapp.permission.MAPS_RECEIVE"/>
<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-feature 
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.gmapsapp.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="YOUR_API_KEY_IS_NOT_PUBLIC"/>

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

</application>

也可以查看以下链接here

【讨论】:

  • 你需要一个真实的设备来测试使用谷歌地图 api 的工作我遇到了同样的问题,因为在模拟器上没有找到谷歌播放服务
  • 它甚至不能在手机上工作;它只显示一个空白的白屏;但是它显示正在搜索 gps
  • 你能把logcat的输出贴在这里吗?
  • 我已经更新了我的答案希望你的问题得到解决
【解决方案3】:

你的logcat我明白了

02-20 07:35:30.271: E/AndroidRuntime(1811): android.content.ActivityNotFoundException:找不到要处理的活动 意图 { act=android.intent.action.VIEW dat=market://details?

实际上,问题与Gingerbreadolder phones 相关,如果他们还没有Play Store installed,则使用the wrong URI。这不是一个安全的假设。大多数开箱即用的 Gingerbread 手机都没有附带它,而且 Google 更新也不一定会安装它。 See the discussion

https://code.google.com/p/android/issues/detail?id=42543

U can get answer for this link

【讨论】:

  • 但我正在研究 JELLYBEAN
  • 已经检查了2nd link I provided :( 除了没有找到任何关于这个问题的东西
【解决方案4】:

尝试在您的布局中将 fill_parent 替换为 match_parent,在 android 2.2 之后不推荐使用 fill_parent
另外,请尝试重新生成 api 密钥。
你在什么设备上测试?

【讨论】:

  • samsung galaxy grand DUOS,我尝试将其更改为 match_parent 但没有帮助
【解决方案5】:

认为问题出在 SHA1 Key 上,

1.获取 API 密钥并将其更新为您的 google_maps_api.xml 文件。 https://developers.google.com/maps/documentation/android-api/start#step_4_get_a_google_maps_api_key

2.生成Sha1

>Open Android Studio.
>Open Your Project.
>Click on Gradle (From Right Side Panel, you will see Gradle Bar)
>Click on Refresh (Click on Refresh from Gradle Bar , you will see List
 Gradle scripts of your Project)
>Click on Your Project (Your Project Name form List(root))
>Click on Tasks
>Click on android
>Double Click on signingReport (You will get SHA1 and MD5 in Run Bar)

How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?

  1. 清理项目 在安卓工作室 菜单 > 构建 > 清理项目

4.在手机或模拟器上运行应用程序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    相关资源
    最近更新 更多