2012-10-31 92 views
2

我已經獲得了我的API密鑰並設置了所有權限。我還設置了它使用Google地圖庫,但我在加載地圖佈局時仍然會看到灰色網格。我也無法讓模擬器使用座標。它說「禁用提供商網絡」,但是當我在手機上調試時,座標工作得很好。MapView仍顯示空白視圖

這是我的佈局文件。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.google.android.maps.MapView 
     android:id="@+id/map_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:enabled="true" 
     android:clickable="true" 
     android:apiKey="0inWE-rpNsby-evq_ORv1bdMuhprR3R38VeZaAw" 
     /> 

    <LinearLayout android:id="@+id/zoom" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 

</RelativeLayout> 

這裏是對應的Java文件。

package com.example.zip.code; 

import android.app.Activity; 
import android.content.Intent; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 

import com.google.android.maps.MapView; 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 

public class OpenMap extends MapActivity { 
    private MapController mapController; 
    private LocationManager locationManager; 
     private String prov; 
     double lat; 
     double lng; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.maplayout); 
     //Criteria crit = new Criteria(); 
     //prov = locationManager.getBestProvider(crit, false); 
     //Location loc = locationManager.getLastKnownLocation(prov); 
     // Get Mapping Controllers etc 
     MapView mapView = (MapView) findViewById(R.id.map_view); 
     mapController = mapView.getController(); 

     // Center on Current Position 
     //mapController.setCenter(new GeoPoint((int) (loc.getLatitude() * 1E6), 
               // (int) (loc.getLongitude() * 1E6))); 
     // mapController.setCenter(new GeoPoint(1924000,-99120000)); 
     mapController.setZoom(11); 
     mapView.setBuiltInZoomControls(true); 

    } 

    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 

    @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      MenuInflater inflater = getMenuInflater(); 
      inflater.inflate(R.menu.mapsettings, menu); 
      return true; 
     } 

     @Override 
     public boolean onOptionsItemSelected(MenuItem item) { 
      // Handle item selection 
      switch (item.getItemId()) { 
       case R.id.zipswap: 
        swapToZip(); 
        return true; 
       default: 
        return super.onOptionsItemSelected(item); 
      } 
     } 

     public void swapToZip(){ 
      Intent i = new Intent(getApplicationContext(), MainActivity.class); 
      startActivity(i); 
     } 
} 

我不知道什麼似乎出錯了。我已經使用了所有需要的東西,但我仍然得到一個灰色的網格。我需要一個單獨的密鑰進行調試嗎?

+0

您的計算機上是否有多個.android文件夾?如果是這樣,請嘗試另一個。我發現我有2. – jasonflaherty

+0

這是一個偉大的地方也可以幫助:http://www.vogella.com/articles/AndroidGoogleMaps/article.html – jasonflaherty

回答

0

如果您運行或調試你的日食,你應該有一個谷歌地圖調試的關鍵,這裏是一個鏈接,可以幫助您得到調試API密鑰

檢查科「獲取SDK調試證書的MD5指紋在

http://code.google.com/android/add-ons/google-apis/mapkey.html

新建鏈接路徑「部分 https://developers.google.com/maps/documentation/android/mapkey

在發佈構建時,您必須用API密鑰替換現有的調試API密鑰。

+0

我已經完成了所有的清單。我已啓用所有網絡服務。 – todaroa

+0

檢查您的系統的Internet連接 – RajeshVijayakumar

+0

您的清單中是否包含所有這些內容? <許可 機器人:名稱= 「com.example.zip.code.permission.MAPS_RECEIVE」 機器人:的ProtectionLevel = 「簽名」/> <使用特徵 機器人:glEsVersion = 「0x00020000」 機器人:需要=」 true「/> <使用權限android:name =」com.example.zip.code.permission.MAPS_RECEIVE「/> <使用權限android:name =」com.google.android.providers.gsf.permission .READ_GSERVICES「​​/> – jasonflaherty