Android Maps API 密钥正确,但地图未显示

发布于 2024-10-04 10:56:25 字数 3545 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不忘初心 2024-10-11 10:56:26

这似乎是清单中某些权限的问题,这是一个 AndroidManifest.xml 的工作示例:

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

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="3" /> 

    <application android:icon="@drawable/icon"
                 android:label="@string/app_name" 
                 android:debuggable="true">   

      <activity android:name="<package>.Activity"
                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>

      <uses-library android:name="com.google.android.maps" ></uses-library>

    </application>

  </manifest>

查看您的清单并检查:

  • INTERNET 权限是否存在
  • 使用-库在那里

It seems to be a problem of some permissions in your manifest, here is a working example of an AndroidManifest.xml :

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

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="3" /> 

    <application android:icon="@drawable/icon"
                 android:label="@string/app_name" 
                 android:debuggable="true">   

      <activity android:name="<package>.Activity"
                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>

      <uses-library android:name="com.google.android.maps" ></uses-library>

    </application>

  </manifest>

Look into your manifest and check if :

  • the INTERNET permission is there
  • the uses-library is there
夏九 2024-10-11 10:56:26

还要确保您在具有 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 only INTERNET for the permission. So android.permission.INTERNET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文