【问题标题】:When using a tethered device to debug, which Google Maps API key do I use?使用联机设备进行调试时,我使用哪个 Google Maps API 密钥?
【发布时间】:2013-04-09 04:14:23
【问题描述】:

我知道有很多关于使用 Google Maps API 密钥的问题,但自从 V1 消失以来,没有一个问题得到解答。我在 MapView 上加载地图图块时遇到问题。我正在使用从调试密钥库派生的 API 密钥,并且正在使用通过 USB 连接的 Nexus 7 进行调试。我相信我在某处读到过,如果您使用 USB 调试,调试密钥将不起作用 - 这是真的吗?如果我无法让虚拟设备在我的机器上运行,我该如何解决这个问题? MapView 显示正常,但我收到“服务器返回 3”错误,我理解这与密钥不匹配有关。这是我的布局文件中的视图,以及我的manfiest:

<com.google.android.maps.MapView
  android:id="@+id/map"
  android:layout_width="fill_parent"
  android:layout_height="100dp"
  android:clickable="true"
  android:apiKey="AIzaSyDXlQso2Xzo4vhLt3gqZAFuoYt081cao8M"
  android:visibility="visible"
/>

清单

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<permission
    android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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"     android:permission="android.permission.ACCESS_FINE_LOCATION">
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name="com.casson.sherpy.MainActivity"
        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>

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDXlQso2Xzo4vhLt3gqZAFuoYt081cao8M"/>

</application>

</manifest>

【问题讨论】:

    标签: android google-maps google-maps-api-3 api-key


    【解决方案1】:

    在启用调试的情况下使用调试键没有问题。这可能是由于您的清单中缺少使用库声明。但我真的建议从 V1 升级到当前版本 - 在那里处理密钥要容易得多(您只需将密钥和应用名称放入网站,而不是放在 xml 中)。

    【讨论】:

    • 感谢您的回答 - 抱歉,如果我不清楚,我实际上在这里使用 V2。我需要另一个用途库吗?我已经有 在那里。很高兴您向我指出了这个方向,但是,我注意到我忘记用自己的 MAPS_RECEIVE 权限替换示例包名称
    • 如果您使用的是 v2,那么您不需要 xml 布局中的键 - 它在清单中的元数据标记中出现一次。
    猜你喜欢
    • 1970-01-01
    • 2018-09-02
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 2012-03-28
    • 2019-04-08
    相关资源
    最近更新 更多