2011-03-31 197 views
0

我在我的應用程序中正確安裝了google map api,所有工作都可以正常使用模擬器。但是,當我將它傳輸到我的手機時,它不再工作(有那個網格的東西),我找不到錯在哪裏。MapView適用於模擬器,但不適用於手機

public class Main extends MapActivity { 
    /** Called when the activity is first created. */ 
    MapView map ; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     map = (MapView)findViewById(R.id.mapview); 
     map.setSatellite(true); 
     List<Overlay> mapOverlays = map.getOverlays(); 
     Drawable drawable = this.getResources().getDrawable(R.drawable.pins); 
     HelloItem itemizedoverlay = new HelloItem(drawable, this); 
     GeoPoint point = new GeoPoint(19240000,-99120000); 
     OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!"); 
     itemizedoverlay.addOverlay(overlayitem); 
     mapOverlays.add(itemizedoverlay); 
     map.setBuiltInZoomControls(true); 
    } 
    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
} 

public class HelloItem extends ItemizedOverlay { 
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); 
private Context mContext; 

public HelloItem(Drawable defaultMarker) { 
    super(boundCenterBottom(defaultMarker)); 
} 
public HelloItem(Drawable defaultMarker, Context context) { 
    super(boundCenterBottom(defaultMarker)); 
    mContext = context; 
    } 

@Override 
protected OverlayItem createItem(int i) { 
    // TODO Auto-generated method stub 
     return mOverlays.get(i); 
} 
public void addOverlay(OverlayItem overlay) { 
    mOverlays.add(overlay); 
    populate(); 
} 
@Override 
public int size() { 
     return mOverlays.size(); 
} 
protected boolean onTap(int index) { 
     OverlayItem item = mOverlays.get(index); 
     AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
     dialog.setTitle(item.getTitle()); 
     dialog.setMessage(item.getSnippet()); 
     dialog.show(); 
     return true; 
    } 

}

+0

這是一個重複的問題。看到類似的問題:http://stackoverflow.com/questions/1809507/android-hello-mapview-tutorial-map-tiles-do-not-load – Brian 2011-03-31 14:33:50

+0

我做了所有這一切,它與日食,但不是在我的手機上正常工作。 – Tsunaze 2011-03-31 14:37:17

+0

缺少互聯網連接? – 2red13 2011-03-31 14:39:18

回答

0

這是因爲你需要使用不同的.keystore,一個是仿真器(調試),一個是設備(釋放)。當您從Google獲取您的debug.keystore MD5 & Map API密鑰時,請遵循相同的步驟。這次您需要爲your_own.keystore獲取這兩個信息,這是用於在設備上發佈的信息。然後在地圖佈局中更改地圖API密鑰,地圖將顯示在您的設備上。

相關問題