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;
}
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为您需要使用不同的.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.