MapView可以在模拟器上运行,但不能在手机上运行

时间:2011-03-31 14:31:24

标签: android google-maps grid android-mapview

我在我的应用上安装了正确的谷歌地图api,一切正常,模拟器。但是,当我将它转移到我的手机时,它不再起作用了(有网格的东西),我找不到什么是错的。

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;
    }

}

1 个答案:

答案 0 :(得分:0)

这是因为您需要使用不同的.keystore,一个用于模拟器(debug),一个用于设备(​​发布)。获取debug.keystore MD5&amp;来自Google的地图API密钥。这次你需要获取your_own.keystore的两个信息,这些信息是在设备上发布的。然后在地图布局中更改地图API密钥,地图将显示在您的设备上。