我在我的应用中使用谷歌地图,代码在设备上完美运行,但地图无法加载!我刚看到一个白色的屏幕!有什么问题 ?
这是代码,请帮忙!
public class MyMap extends MapActivity {
private MapView map;
private MapController controller;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initMapView();
initMyLocation();
}
/** Find and initialize the map view. */
private void initMapView() {
map = (MapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(true);
map.setBuiltInZoomControls(true);
}
/** Start tracking the position on the map. */
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
//overlay.enableCompass(); // does not work in emulator
overlay.runOnFirstFix(new Runnable() {
public void run() {
// Zoom in to current location
controller.setZoom(8);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
@Override
protected boolean isRouteDisplayed() {
// Required by MapActivity
return false;
}
}
答案 0 :(得分:2)
将地图api密钥放在xml中here是获取地图api密钥的教程
答案 1 :(得分:0)
在maplayout.xml中创建您的google地图api密钥和有害生物
android:apiKey =“你的api密钥”
可自由使用