我的地图不会显示。我什至没有在 Log Cat 中获得地图网格或任何错误消息。我没有收到任何类型的“无法通过 google api 进行身份验证”或类似的东西(这让我相信我的 api 密钥是正确的)。我根本没有得到任何类型的地图。
配置和清单
- 我正在使用 android 模拟器(我检索了调试密钥来生成我的 API 密钥,因为我没有将其导出为 apk)
- 我从 jdk1.7 适当地获得了 SHA1 并调试密钥库
- 我在 API 开发者控制台上同时启用了 GoogleMaps V2 和 GooglMapsAndroidV2
- 我在清单中启用了所有必需和推荐的权限、元数据和功能(例如 openGL 2),如下所示
- 我已启用 Android PrivateLibraries a。Google-play-services.jar b. 安卓支持-v4.jar
- 我有 Android 依赖项:Google-play-services_lib.jar
- 我已经在这篇文章的底部复制了我的 project.properties 和 proguard 文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.proximitystuff"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.proximitystuff.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"/>
<!-- 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:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<uses-library
android:name="com.google.android.maps"/>
<activity
android:name="com.example.proximitystuff.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>
<activity
android:name="com.example.proximitystuff.MyMapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAPACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.example.proximitystuff.ProxyBackgroundCheck"
android:enabled="true"
android:permission="com.example.ADAMS_PROX_PERMISSION" >
</service>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBnQNgn166qfatch_xcFwL8K0AfVHBYcGA"/>
</application>
</manifest>
Java 代码和 XML 布局:我的主要活动使用一个按钮进入屏幕截图中显示的地图活动。这个地图活动的代码被限制在最基本的功能上,它仍然无法工作。我的一个理论是,因为这个类没有从“FragmentActivity”继承,所以它不能使用 xml 片段(如果是这种情况,我希望我至少会在日志中得到某种类型的错误)。
package com.example.proximitystuff;
import android.app.Activity;
import android.os.Bundle;
public class MyMapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
}
}
My XML layout is using the most basic layout possible.
<?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"/>
项目属性
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library.reference.1=../google-play-services_lib
Proguard(以防万一这是错误的):
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}