Android Maps API 密钥正确,但地图未显示
TL;DR
我们需要移至
<uses-permission android:name="android.permission.INTERNET"/>
下
</application>
原始问题
嗨, 我是android开发的新手。 我尝试了“Hello Google Maps”教程,但无法查看地图。 我注册了 API 密钥。 我正在使用安装在“D”驱动器上的 Eclipe。使用以下命令从我的 jdk 安装的 bin 文件夹中获取 MD5 指纹:
c:\program files\java\jdk 1.6\bin> keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\Owner\.android\debug.keystore" -storepass android -keypass android
我得到了这个指纹
21:17:B1:D8: 01:BD:F2:5A:9F:C9:A3:01:96:FA:9A:5B
用它来查找 API 密钥并得到这个
"0Gm7C3R3R2K1pmQGuGkS0rx582TWJEBdJwryFrA"
使用以下内容布局中的代码
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0Gm7C3R3R2K1pmQGuGkS0rx582TWJEBdJwryFrA"
/>
静态地图不显示。 请赐教我这一点。 预先感谢
LogCat 错误日志
11-25 03:14:38.432: ERROR/AndroidRuntime(10857): ERROR: thread attach failed
11-25 03:14:42.162: ERROR/AndroidRuntime(10866): ERROR: thread attach failed
11-25 03:14:45.562: ERROR/AndroidRuntime(10877): ERROR: thread attach failed
11-25 03:14:47.402: ERROR/MapActivity(10885): Couldn't get connection factory client
11-25 03:14:50.652: ERROR/PackageInstallationReceiver(6465): Remove /data/local/tmp/com.testGoogleMap.apk Fail!
11-25 03:14:58.952: ERROR/wpa_supplicant(1683): wpa_supplicant_ctrl_iface_ap_scan: 2
11-25 03:14:58.952: ERROR/wpa_supplicant(1683): Scan request
11-25 03:14:59.802: ERROR/wpa_supplicant(1683): wpa_supplicant_ctrl_iface_ap_scan: 1
我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.helloGoogleMaps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-permission android:name="android.permission.ACCESS_INTERNET"/>
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
修改清单
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="7" />
TL;DR
We need to move
<uses-permission android:name="android.permission.INTERNET"/>
under
</application>
Original question
Hi,
I am a newbie in android development.
I tried the "Hello Google Maps" tutorial and I am not able to view the map.
I signed up for API key.
I am using Eclipe which is installed in on the "D" drive. Used following command to obtain MD5 fingerprint from the bin folder of my jdk installation:
c:\program files\java\jdk 1.6\bin> keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\Owner\.android\debug.keystore" -storepass android -keypass android
I got this fingerprint
21:17:B1:D8:01:BD:F2:5A:9F:C9:A3:01:96:FA:9A:5B
Used this to find the API key and got this
"0Gm7C3R3R2K1pmQGuGkS0rx582TWJEBdJwryFrA"
Used the following code in layout
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0Gm7C3R3R2K1pmQGuGkS0rx582TWJEBdJwryFrA"
/>
Still map is not displayed.
Please enlighten me on this.
Thanks in advance
LogCat Error log
11-25 03:14:38.432: ERROR/AndroidRuntime(10857): ERROR: thread attach failed
11-25 03:14:42.162: ERROR/AndroidRuntime(10866): ERROR: thread attach failed
11-25 03:14:45.562: ERROR/AndroidRuntime(10877): ERROR: thread attach failed
11-25 03:14:47.402: ERROR/MapActivity(10885): Couldn't get connection factory client
11-25 03:14:50.652: ERROR/PackageInstallationReceiver(6465): Remove /data/local/tmp/com.testGoogleMap.apk Fail!
11-25 03:14:58.952: ERROR/wpa_supplicant(1683): wpa_supplicant_ctrl_iface_ap_scan: 2
11-25 03:14:58.952: ERROR/wpa_supplicant(1683): Scan request
11-25 03:14:59.802: ERROR/wpa_supplicant(1683): wpa_supplicant_ctrl_iface_ap_scan: 1
My manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.helloGoogleMaps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-permission android:name="android.permission.ACCESS_INTERNET"/>
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
Modified manifest
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".HelloGoogleMaps"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="7" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是清单中某些权限的问题,这是一个 AndroidManifest.xml 的工作示例:
查看您的清单并检查:
INTERNET
权限是否存在使用-库
在那里It seems to be a problem of some permissions in your manifest, here is a working example of an AndroidManifest.xml :
Look into your manifest and check if :
INTERNET
permission is thereuses-library
is there还要确保您在具有 Google API 映像的模拟器上运行它,否则您将不会在模拟器上安装 Google 地图。
更新:刚刚发现了错误。它不是
ACCESS_INTERNET
,而只是INTERNET
的权限。所以android.permission.INTERNET
。Also make sure you run it on an emulator with a Google API image otherwise you are not going to have Google Maps installed on the emulator.
Update: Just spotted the mistake. It is not
ACCESS_INTERNET
but onlyINTERNET
for the permission. Soandroid.permission.INTERNET
.