2014-06-18 93 views
1

我已經開始創建一個使用Google Map Api V2的演示應用程序,我遵循Google指南http://developer.android.com/google/play-services/maps.html & http://www.truiton.com/2013/05/android-mapfragment-example/Google Map API版本2無法聯繫Google服務器

地圖活動正在加載,但實際谷歌地圖沒有加載,並顯示錯誤消息:

10月6日至18日:19:23.717:I /谷歌地圖的Android API(29990):無法聯繫Google服務器。連接建立後將進行另一次嘗試。

06-18 10:19:38.903:E谷歌地圖Android API(29990):無法加載地圖。聯繫Google服務器時出錯。這可能是一個身份驗證問題(但可能是由於網絡錯誤)。

可能的錯誤是由於造成的事實,我對3G /邊緣比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

由於

回答

相關問題