简体   繁体   English

Android地图:无法加载地图。 无法联系Google服务器

[英]Android Maps: Failed to load map. Could not contact Google servers

This bug has been persistent for forever. 这个bug一直存在。 (I made sure that "Google Maps Android API v2" is the one turned on.) (我确保“谷歌地图Android API v2”是打开的。)

Here's the MainActivity.java: 这是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;
    }     
}

Manifest: 表现:

    <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: 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>

Please help! 请帮忙! I'm not sure what went wrong...though I did end up following/combining various tutorials because none of them worked on their own. 我不确定出了什么问题......虽然我最终关注/结合了各种教程,因为它们都没有自己的工作。

1. The first problem I see is here: 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"/>

remove this line: class="com.google.android.gms.maps.SupportMapFragment" 删除此行:class =“com.google.android.gms.maps.SupportMapFragment”

and set android:name as: 并将android:name设置为:

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

2. Remove this line from the manifest file: 2.从清单文件中删除此行:

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

This is Google Maps API V1 permission and shouldn't be use in API V2 . 这是Google Maps API V1权限,不应在API V2使用。

Take a look at this blog post and make sure are doing everything correctly: 看看这篇博客文章,确保正确完成所有事情:

Google Maps API V2 Google Maps API V2

3. The problem you describing usually derives from a problem in generating or registering the API key using the API Console, If you are positive that you have made all the steps correctly then I suggest you to delete the debug.keystore folder, compile some project in Eclipse (this will result in a new SHA1 key) and register the key again using the console. 3.您描述的问题通常源于使用API​​控制台生成或注册API密钥时出现的问题,如果您肯定已经正确地完成了所有步骤,那么我建议您删除debug.keystore文件夹,编译一些项目在Eclipse中(这将产生一个新的SHA1密钥)并使用控制台再次注册密钥。 Take a look at this blog post I wrote and make sure I are doing all the steps right: 看看我写的这篇博文,确保我正在做所有正确的步骤:

Google Map API V2 Key Google Map API V2密钥

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM