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

发布于 2024-10-28 19:51:43 字数 2077 浏览 1 评论 0原文

我在我的应用程序上正确安装了谷歌地图 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;
    }

}

I installed correctly google map api on my app, all works fine with the emulator. But when i transfer it to my phone it doesn't work anymore (there is that grid thing), and i can't find what's wrong.

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-11-04 19:51:43

发生这种情况是因为您需要使用不同的.keystore,一个用于模拟器(调试),一个用于设备(​​发布)。当您获取 debug.keystore MD5 和 MD5 时,请遵循相同的过程。来自 Google 的映射 API 密钥。这次你需要获取your_own.keystore的这两个信息,该信息用于在设备上发布。然后更改地图布局中的地图 API 密钥,地图将显示在您的设备上。

This happens because you need to use different .keystore, one is for emulator(debug), one is for device(release). follow the same procedures when you acquired your debug.keystore MD5 & Map API Key from Google. this time you need to acquire both information for your_own.keystore, which is for release on device. then change the Map API Key in your map layout, the map will shown on your device then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文