java - Android map : Failed to load map. 无法联系谷歌服务器

标签 java android xml google-maps

这个错误一直存在。 (我确保打开了“Google Maps Android API v2”。)

这是 MainActivity.java:

package com.example.maptest;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity { 

    @Override     
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }     
}

list :

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

     <permission
        android:name="com.example.maptest.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission 
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>


    <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    <uses-feature
        android:name="android.hardware.location"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.location.network"
        android:required="true" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature
        android:name="android.hardware.wifi"
        android:required="true" />

    <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.maptest.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>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAoDwhSzOopQ3g8NBe7d0WblR72TkmnVPU" />


    </application>

</manifest>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >


    <fragment 
    class="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"/>

</RelativeLayout>

求助!我不确定哪里出了问题……尽管我最终还是遵循/结合了各种教程,因为它们都不能独立运行。

最佳答案

1. 我看到的第一个问题是:

<fragment 
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>

删除这一行: class="com.google.android.gms.maps.SupportMapFragment"

并将android:name设置为:

 android:name="com.google.android.gms.maps.SupportMapFragment"

2.从 list 文件中删除这一行:

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

这是 Google map API V1 权限,不应在 API V2 中使用。

看看这篇博文,确保一切都正确:

Google Maps API V2

3. 您所描述的问题通常源于使用 API 控制台生成或注册 API key 时出现的问题,如果您确信自己已正确完成所有步骤,那么我建议您删除 debug.keystore 文件夹,在 Eclipse 中编译一些项目(这将产生一个新的 SHA1 key )并使用控制台再次注册该 key 。看看我写的这篇博文,确保我做的所有步骤都是正确的:

Google Map API V2 Key

关于java - Android map : Failed to load map. 无法联系谷歌服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16260692/

相关文章:

xml - 如何捕获另一个XPath查询中递增Xpath查询的所有匹配项?

xml - Soap xml 响应使用 xsd 文件进行验证

php - Magento 中隐藏的左侧导航但可见的帐户仪表板链接

java - Java中的SHA和测试工具

java - 从 SQLite 列添加数据

android - 如何使用位图发送到另一个应用程序

android - 通过 React Native 和 Expo 在 WebView 中使用本地文件中的 CSS

java - 使用命名约定插件拒绝直接访问 Struts2 中的 JSP 文件

java - 设置带约束的分区java

java - 何时关闭带有 DAO 模式的 SQL 连接?