2013-07-05 39 views
0

我有谷歌地圖的Android API V2的一個項目,但我在手機上運行這個項目的logcat有錯誤我有錯誤了谷歌地圖的Android API V2沒有加載

Falied加載map.Error聯繫Google服務器。這是可能的身份驗證問題(但可能是由於網絡錯誤)

所以我的代碼是在類HomeActivity這裏

package com.mpa.emvi; 

import com.mpa.emvi.R; 
import android.support.v4.app.FragmentActivity; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

import android.os.Bundle; 
//import android.app.Activity; 
import android.view.Menu; 

public class HomeActivity extends FragmentActivity { 

    private GoogleMap mMap; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home); 
     setUpMapIfNeeded(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     setUpMapIfNeeded(); 
    } 

    private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    private void setUpMap() { 
     mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
    } 

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

} 

這是一個佈局HomeActivity

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/send" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".HomeActivity" > 

    <fragment xmlns:map="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true"/> 

    <Button 
     android:id="@+id/sendDS" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/map" 
     android:layout_centerHorizontal="true" 
     android:text="@string/send_destination"/> 

</RelativeLayout> 

這是一個清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.mpa.emvi" 
    android:versionCode="2" 
    android:versionName="2.1.0"> 
    <permission 
    android:name="com.mpa.emvi.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 
    <uses-permission android:name="com.mpa.emvi.permission.MAPS_RECEIVE"/> 
    <!-- Copied from Google Maps Library/AndroidManifest.xml. --> 
    <uses-sdk 
     android:minSdkVersion="11" 
     android:targetSdkVersion="14"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <!-- External storage for caching. --> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <!-- My Location --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <!-- Maps API needs OpenGL ES 2.0. --> 
    <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" > 
     <activity 
      android:name="com.mpa.emvi.HomeActivity" 
      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="My-Release-API-KEY"/> 
    </application> 

</manifest> 

你看到我的代碼。你有什麼事? 好吧我試着在這個問題上查找同樣的問題,我嘗試重新生成新的API密鑰,但不工作。 在我的項目中,導入一個谷歌服務庫和android支持v4。 在谷歌控制檯我打開谷歌地圖android api v2服務。 在谷歌控制檯android應用程序:my-SHA1-series; com.mpa.emvi

好吧持久我是一個新手android程序員,對不起我的英語很差。

感謝每一個答案。

+0

檢查您是否在谷歌api控制檯啓用谷歌地圖爲Android – Raghunandan

+0

是的,我已經啓用谷歌地圖android api v2。 –

+0

檢查您是否在地圖項目中正確引用了Google Play服務庫項目。 – Raghunandan

回答

0

好吧,現在我的應用程序顯示map.I忘記刪除舊的apk文件,並重新安裝新的apk文件它的工作。謝謝任何答覆謝謝。

0

您是否在清單文件中添加了您的Api密鑰?

+0

好吧,現在我的應用程序顯示map.I忘記刪除舊的apk文件,並重新安裝新的apk文件它的工作。謝謝任何答覆謝謝。 –