2012-06-22 33 views
0

我想實現谷歌地圖,但我現在面臨的一些問題的。 問題是,當我加載我的應用程序時,它只顯示地圖的網格(而不是地圖的圖像)。谷歌地圖Android中只顯示網格

這裏是我的代碼...任何人都可以看到這個問題?

的Xml主要

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <com.google.android.maps.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/map_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:apiKey=" api key" 
     android:clickable="true" 
     android:enabled="true" /> 

    </LinearLayout> 

清單文件

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

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


    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".NewMapActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <uses-library android:name="com.google.android.maps" /> 
    </application> 

</manifest> 

的Java類

package info.org.NewMap; 

import android.os.Bundle; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView; 
public class NewMapActivity extends MapActivity { 
    /** Called when the activity is first created. */ 

    private MapView mapView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mapView = (MapView) findViewById(R.id.map_view);  
     mapView.setBuiltInZoomControls(true); 
    } 

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

其次Java文件

package info.org.NewMap; 
import java.util.ArrayList; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.graphics.drawable.Drawable; 
import com.google.android.maps.ItemizedOverlay; 
import com.google.android.maps.OverlayItem; 

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> { 

    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 

    private Context context; 

    public CustomItemizedOverlay(Drawable defaultMarker) { 
     super(boundCenterBottom(defaultMarker)); 
    } 

    public CustomItemizedOverlay(Drawable defaultMarker, Context context) { 
     this(defaultMarker); 
     this.context = context; 
    } 

    @Override 
    protected OverlayItem createItem(int i) { 
     return mapOverlays.get(i); 
    } 

    @Override 
    public int size() { 
     return mapOverlays.size(); 
    } 

    @Override 
    protected boolean onTap(int index) { 
     OverlayItem item = mapOverlays.get(index); 
     AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
     dialog.setTitle(item.getTitle()); 
     dialog.setMessage(item.getSnippet()); 
     dialog.show(); 
     return true; 
    } 

    public void addOverlay(OverlayItem overlay) { 
     mapOverlays.add(overlay); 
     this.populate(); 
    } 
} 
+0

你給正確的地圖API密鑰 –

+0

是你是對的問題是API密鑰.. – Youddh

回答

2

如果你已經使用debug.keystore以獲取地圖API密鑰,那麼它不會顯示的地圖瓦片,當你啓動與自己的私人密鑰庫簽署的應用程序。 你簽了你的應用程序了嗎?

若要登錄應用程序,你必須使用你用來簽名的應用程序相同的密鑰庫得到谷歌的API密鑰映射(未debug.keystore)。

+0

親愛的,我的問題是解決了,但我建立API密鑰從debug.keystore,它的工作好。 – Youddh

+0

+1您R右如果我從debug.keystore它的工作,但是當我創建我的應用程序的APK是研發問題創建我的API密鑰,所以我有我的應用程序的密鑰庫由於創造... – Youddh

1

您是否添加了以下權限您的應用程序在你的AndroidManifest.xml文件

  1. INTERNET
  2. ACCESS_FINE_LOCATION
  3. ACCESS_COARSE_LOCATION

的問候, Aqif Hamid

+0

我已經考慮到這樣的權限我認爲這是沒有問題..聽到感謝 – Youddh

-1

禁用代理服務器....如果代理服務器啓用地圖將不會工作。

+0

怎會做到這一點,它與什麼有什麼關係? – Mugen