我正在尝试实施Google maps API V2,但地图没有出现。片段显示为+/-符号用于缩放,Google显示在左侧。
我写了一个简单的代码,它应该只显示地图。它显示了logcat中的身份验证失败,但我100%确定我做了正确的步骤: 1)开始使用Google Android API V2服务 2)使用SHA1获取密钥;使用项目的com.example.action(包名)..
请看一下并帮助......
XML文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>
JAVA文件:
package com.example.action;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.action"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<!-- Specify the correct minSDK and targetSDK versions. -->
<!-- Google Maps related permissions -->
<permission android:name="com.ecs.google.maps.v2.actionbarsherlock.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
<!-- Network connectivity permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Access Google based webservices -->
<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"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light" >
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCIrEGMEBSP8bU2jorUlmmPLVpVYngyPUE"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.action.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>
</manifest>
,该应用程序显示:
logcat的:
03-21 15:37:05.101: D/dalvikvm(8393): GC_EXPLICIT freed 16K, 43% free 4308K/7431K, external 592K/1042K, paused 51ms
03-21 15:41:41.140: I/ApplicationPackageManager(8685): cscCountry is not German : INU
03-21 15:41:41.187: W/dalvikvm(8685): VFY: unable to resolve virtual method 6231: Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.onHoverEvent (Landroid/view/MotionEvent;)Z
03-21 15:41:41.187: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x0000
03-21 15:41:41.187: D/dalvikvm(8685): VFY: dead code 0x0003-0004 in Lcom/actionbarsherlock/internal/widget/ActionBarContainer;.onHoverEvent (Landroid/view/MotionEvent;)Z
03-21 15:41:41.203: W/dalvikvm(8685): VFY: unable to resolve virtual method 4872: Landroid/widget/FrameLayout;.getAlpha ()F
03-21 15:41:41.203: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:41.203: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.getAlpha ()F
03-21 15:41:41.203: W/dalvikvm(8685): VFY: unable to resolve virtual method 4874: Landroid/widget/FrameLayout;.getTranslationY ()F
03-21 15:41:41.203: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:41.203: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.getTranslationY ()F
03-21 15:41:41.203: W/dalvikvm(8685): VFY: unable to resolve virtual method 4878: Landroid/widget/FrameLayout;.setAlpha (F)V
03-21 15:41:41.203: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:41.203: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.setAlpha (F)V
03-21 15:41:41.203: W/dalvikvm(8685): VFY: unable to resolve virtual method 4886: Landroid/widget/FrameLayout;.setTranslationY (F)V
03-21 15:41:41.203: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:41.210: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.setTranslationY (F)V
03-21 15:41:41.218: W/dalvikvm(8685): VFY: unable to resolve virtual method 4536: Landroid/view/ViewGroup;.getAlpha ()F
03-21 15:41:41.218: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:41.218: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.getAlpha ()F
03-21 15:41:41.218: W/dalvikvm(8685): VFY: unable to resolve virtual method 4547: Landroid/view/ViewGroup;.getTranslationX ()F
03-21 15:41:41.218: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:41.218: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.getTranslationX ()F
03-21 15:41:41.218: W/dalvikvm(8685): VFY: unable to resolve virtual method 4548: Landroid/view/ViewGroup;.getTranslationY ()F
03-21 15:41:41.218: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:41.218: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.getTranslationY ()F
03-21 15:41:41.218: W/dalvikvm(8685): VFY: unable to resolve virtual method 4572: Landroid/view/ViewGroup;.setAlpha (F)V
03-21 15:41:41.218: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:41.218: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.setAlpha (F)V
03-21 15:41:41.218: W/dalvikvm(8685): VFY: unable to resolve virtual method 4577: Landroid/view/ViewGroup;.setTranslationX (F)V
03-21 15:41:41.226: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:41.226: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.setTranslationX (F)V
03-21 15:41:41.226: W/dalvikvm(8685): VFY: unable to resolve virtual method 4578: Landroid/view/ViewGroup;.setTranslationY (F)V
03-21 15:41:41.226: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:41.226: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup;.setTranslationY (F)V
03-21 15:41:41.250: W/dalvikvm(8685): VFY: unable to resolve virtual method 7092: Lcom/actionbarsherlock/internal/widget/ActionBarView$HomeView;.onHoverEvent (Landroid/view/MotionEvent;)Z
03-21 15:41:41.250: D/dalvikvm(8685): VFY: replacing opcode 0x6e at 0x0000
03-21 15:41:41.250: D/dalvikvm(8685): VFY: dead code 0x0003-0004 in Lcom/actionbarsherlock/internal/widget/ActionBarView$HomeView;.dispatchHoverEvent (Landroid/view/MotionEvent;)Z
03-21 15:41:41.250: W/dalvikvm(8685): VFY: unable to resolve virtual method 4876: Landroid/widget/FrameLayout;.onPopulateAccessibilityEvent (Landroid/view/accessibility/AccessibilityEvent;)V
03-21 15:41:41.250: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x0006
03-21 15:41:41.320: D/dalvikvm(8685): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
03-21 15:41:41.320: W/dalvikvm(8685): VFY: unable to resolve instance field 47
03-21 15:41:41.320: D/dalvikvm(8685): VFY: replacing opcode 0x52 at 0x0012
03-21 15:41:41.320: D/dalvikvm(8685): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
03-21 15:41:41.429: D/dalvikvm(8685): GC_CONCURRENT freed 212K, 46% free 3051K/5639K, external 419K/517K, paused 4ms+4ms
03-21 15:41:41.632: D/dalvikvm(8685): GC_CONCURRENT freed 130K, 43% free 3440K/5959K, external 419K/517K, paused 4ms+19ms
03-21 15:41:41.750: W/dalvikvm(8685): Unable to resolve superclass of Lmaps/aj/r; (667)
03-21 15:41:41.750: W/dalvikvm(8685): Link of class 'Lmaps/aj/r;' failed
03-21 15:41:41.750: W/dalvikvm(8685): Unable to resolve superclass of Lmaps/ay/an; (6038)
03-21 15:41:41.750: W/dalvikvm(8685): Link of class 'Lmaps/ay/an;' failed
03-21 15:41:41.750: W/dalvikvm(8685): Unable to resolve superclass of Lmaps/c/i; (6269)
03-21 15:41:41.750: W/dalvikvm(8685): Link of class 'Lmaps/c/i;' failed
03-21 15:41:41.750: E/dalvikvm(8685): Could not find class 'maps.c.i', referenced from method maps.e.al.a
03-21 15:41:41.750: W/dalvikvm(8685): VFY: unable to resolve new-instance 6474 (Lmaps/c/i;) in Lmaps/e/al;
03-21 15:41:41.750: D/dalvikvm(8685): VFY: replacing opcode 0x22 at 0x0091
03-21 15:41:41.804: D/dalvikvm(8685): VFY: dead code 0x0093-00a0 in Lmaps/e/al;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;Z)Lmaps/e/al;
03-21 15:41:41.835: I/ApplicationPackageManager(8685): cscCountry is not German : INU
03-21 15:41:41.890: D/dalvikvm(8685): GC_CONCURRENT freed 239K, 42% free 3710K/6343K, external 419K/517K, paused 3ms+5ms
03-21 15:41:42.148: D/dalvikvm(8685): GC_CONCURRENT freed 346K, 42% free 3929K/6663K, external 419K/517K, paused 4ms+5ms
03-21 15:41:42.320: D/dalvikvm(8685): GC_EXTERNAL_ALLOC freed 168K, 40% free 4024K/6663K, external 444K/517K, paused 62ms
03-21 15:41:42.546: W/dalvikvm(8685): VFY: unable to resolve virtual method 4443: Landroid/view/View;.jumpDrawablesToCurrentState ()V
03-21 15:41:42.546: D/dalvikvm(8685): VFY: replacing opcode 0x6e at 0x0056
03-21 15:41:42.578: D/libEGL(8685): loaded /system/lib/egl/libGLES_hgl.so
03-21 15:41:42.585: W/dalvikvm(8685): VFY: unable to resolve virtual method 4932: Landroid/widget/LinearLayout;.getAlpha ()F
03-21 15:41:42.585: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:42.585: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout;.getAlpha ()F
03-21 15:41:42.585: W/dalvikvm(8685): VFY: unable to resolve virtual method 4935: Landroid/widget/LinearLayout;.getTranslationX ()F
03-21 15:41:42.585: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000b
03-21 15:41:42.585: D/dalvikvm(8685): VFY: dead code 0x000e-000f in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout;.getTranslationX ()F
03-21 15:41:42.585: W/dalvikvm(8685): VFY: unable to resolve virtual method 4947: Landroid/widget/LinearLayout;.setAlpha (F)V
03-21 15:41:42.593: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:42.593: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout;.setAlpha (F)V
03-21 15:41:42.593: W/dalvikvm(8685): VFY: unable to resolve virtual method 4954: Landroid/widget/LinearLayout;.setTranslationX (F)V
03-21 15:41:42.593: D/dalvikvm(8685): VFY: replacing opcode 0x6f at 0x000a
03-21 15:41:42.593: D/dalvikvm(8685): VFY: dead code 0x000d-000d in Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout;.setTranslationX (F)V
03-21 15:41:42.601: D/BRCM_EGL(8685): eglCreateContext() context: 0x1a0868, VC context 1, Thread 8706
03-21 15:41:42.609: D/BRCM_EGL(8685): eglCreateWindowSurface() surface: 0x1a08d8, VC surface: 1, Thread: 8706
03-21 15:41:42.609: D/BRCM_EGL(8685): eglMakeCurrent(0x1a0868, 0x1a08d8, 0x1a08d8) Thread: 8706
03-21 15:41:49.171: D/dalvikvm(8685): GC_CONCURRENT freed 233K, 39% free 4237K/6855K, external 826K/1042K, paused 4ms+6ms
03-21 15:41:52.007: E/Google Maps Android API(8685): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
03-21 15:41:52.015: E/Google Maps Android API(8685): Ensure that the following correspond to what is in the API Console: Package Name: com.example.action, API Key: AIzaSyCIrEGMEBSP8bU2jorUlmmPLVpVYngyPUE, Certificate Fingerprint: A76E6DC98764157ACBA297873AE9E462707E0436
03-21 15:41:52.023: I/Google Maps Android API(8685): Failed to contact Google servers. Another attempt will be made when connectivity is established.
03-21 15:41:52.882: D/BRCM_EGL(8685): eglMakeCurrent(NULL) Thread: 8706
03-21 15:41:52.882: D/BRCM_EGL(8685): eglDestroySurface() surface: 0x1a08d8, android window 0x1a9f50, Thread: 8706
03-21 15:42:07.554: E/Google Maps Android API(8685): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
03-21 15:42:41.500: D/dalvikvm(8685): GC_CONCURRENT freed 681K, 43% free 4239K/7367K, external 592K/1042K, paused 4ms+4ms
答案 0 :(得分:0)
这是API密钥问题。使用默认调试密钥库创建SHA并获取API密钥并在同一系统上再次创建APK。