2013-07-23 183 views
0

目前我正在Google地圖上工作,並且爲了創建我遵循android開發人員網站中的所有說明。但我不能在我的設備中加載地圖,但我可以指出不同的地方和所有。我的設備是否支持Google API V2?有什麼方法可以在我的設備上查看地圖嗎?我的設備版本是2.3.3。谷歌地圖API v2不能在設備上工作

+0

您是否在不同的設備上測試您的應用程序? – TheFlash

+1

你可以在這裏粘貼你的logcat嗎? – RAAAAM

+0

07-23 13:01:18.726:E/MapActivity(2640):無法獲取連接工廠的客戶...... 我可以查看網格以及所有的點,但地圖上沒有加載 –

回答

1

我有一個工作的GoogleMaps v2應用程序,最初我有你所描述的相同的問題。 在我的情況下,問題在於我使用的API密鑰與我用於簽署應用程序的證書(調試/開發階段和發佈Play應用程序的版本)不匹配。 該應用程序正在處理從10開始的所有Android版本(所以它適用於2.3.3)。 從日誌錯誤來看,您可能會遇到連接問題。你有沒有聲明適當的使用權限?它應該是:

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

這裏是主要的地圖代碼的一小段:

public class LocationActivity extends MapActivity { 


    private MapController mapController; 
    private MapView mapView; 
    private LocationManager locationManager; 
    private MyLocationOverlay myLocationOverlay; 

    public void onCreate(Bundle bundle) { 
     super.onCreate(bundle); 
     if(Utils.isRelease(getApplicationContext())) { 
      setContentView(R.layout.location_activity_release); // bind the layout to the activity 
     } else { 
      setContentView(R.layout.location_activity); // bind the layout to the activity 
     } 

     // Configure the Map 
     mapView = (MapView) findViewById(R.id.mapview); 
     mapView.setBuiltInZoomControls(true); 
     mapView.setSatellite(false); 
     mapController = mapView.getController(); 
     mapController.setZoom(15); // Zoon 1 is world view 

     myLocationOverlay = new MyLocationOverlay(this, mapView); 
     mapView.getOverlays().add(myLocationOverlay); 
     // More map configurations follow... 

而且佈局(請注意在Maps API密鑰的差異): location_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:apiKey="@string/google_maps_v1_api_key" 
    android:clickable="true" /> 

和(location_activity_release.xml):

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:apiKey="@string/google_maps_v1_api_key_release" 
    android:clickable="true" /> 
+0

如何獲得在V1的API密鑰?我不和我擁有它,只是有V2 API密鑰。 –

+0

你在項目中使用「google_maps_v1_api_key」?有沒有辦法用在V2 API密鑰來檢查應用程序有更低版本的設備? –