甚至在手机上也没有显示Android地图,只能看到白色屏幕

时间:2014-02-20 07:16:30

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

我的项目有一个地图活动,其中包含使用意图链接的其他活动。然而,所有其他活动都已被看到;地图只显示手机上的空白屏幕,并在模拟器上显示错误“更新Google Play服务”。请帮忙

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>

我的logcat

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.

5 个答案:

答案 0 :(得分:1)

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

我已经更新了我的答案并显示了我的代码与您的代码略有不同但可能对您有所帮助

enter image description here

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

答案 1 :(得分:1)

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

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

答案 2 :(得分:1)

来自你的logcat我看到了

  

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

实际上,问题与Gingerbreadolder phones使用the wrong URI有关,如果他们还没有Play Store installed。这不是一个安全的假设。大多数开箱即用的姜饼手机都没有配备它,谷歌更新不一定安装它。 See the discussion

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

U can get answer for this link

答案 3 :(得分:0)

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

答案 4 :(得分:0)

认为问题是SHA1密钥,

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

after 0 {
    chan configure stdin -blocking 0 -buffering none
    fileevent stdin readable {
        exit
    }
    after 20000 exit
    while true {
        puts -nonewline .
        update
    }
}
vwait forever

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

  1. 清洁项目 在android工作室 菜单&gt;构建&gt;清洁项目
  2. 4.在手机或模拟器上运行应用程序

相关问题