Google Map API版本2无法与Google服务器联系

时间:2014-06-18 17:41:05

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

我已经开始创建一个使用Google Map Api V2的演示应用,我按照Google指南http://developer.android.com/google/play-services/maps.html& http://www.truiton.com/2013/05/android-mapfragment-example/

正在加载地图活动,但未加载实际的Google地图,并显示错误消息:

06-18 10:19:23.717:I / Google Maps Android API(29990):无法联系Google服务器。建立连接时将进行另一次尝试。

06-18 10:19:38.903:E / Google Maps Android API(29990):无法加载地图。联系Google服务器时出错这可能是一个身份验证问题(但可能是由于网络错误)。

错误是由于我在 3G / Edge 这个慢于比4G或Wifi 的事实引起的,反过来可能导致连接到超时???

以下是我的活动:

package com.example.theappdallas;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MapViewActivity extends FragmentActivity {

    private GoogleMap map = null; 
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_view);

         map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map1)).getMap();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.map_view, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


}//end class

以下是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/map1"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        class="com.google.android.gms.maps.MapFragment" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/map_view_directions" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/map_view_pin" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/map_view_search" />
    </LinearLayout>

</LinearLayout>

以下是我的清单(我已设置所有权限并提供了新的API密钥):

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

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

       <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
       <!-- permissions -->
     <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-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <permission android:name="com.example.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <uses-permission android:name="android.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


    <!-- SplashScreen -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="4452000" />

        <activity
            android:name="com.example.theappdallas.SplashScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!-- API key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="*************************" />


        <!-- MainMenuActivity -->
        <activity
            android:name="com.example.theappdallas.MainMenuActivity"
            android:label="@string/title_activity_main_menu"
            android:screenOrientation="portrait" >
        </activity>
        <!-- MapViewActivity -->
        <activity
            android:name="com.example.theappdallas.MapViewActivity"
            android:label="@string/title_activity_map_view" >
        </activity>
    </application>

</manifest>

MapViewActivity的屏幕截图:

enter image description here

由于

1 个答案:

答案 0 :(得分:1)

我怀疑由于连接超时,地图没有显示;问题很可能是API密钥。 I would follow these instructions closely to make sure you are generating the API key correctly.如果您对此过程有任何具体问题,请与我们联系。此外,您应该从发布的代码中删除您的API密钥。