gpt4 book ai didi

android - 谷歌地图 Android API v2 : GoogleMap is null

转载 作者:太空宇宙 更新时间:2023-11-03 11:51:11 24 4
gpt4 key购买 nike

我正在尝试使用 MapView 类来显示 GoogleMap,但没有成功,因为大多数代码示例都使用了我不想要的 MapFragment。

我正在使用 Google Maps Android API v2。

起初,只是为了测试 here from Google's example ,我设法获得了要显示的典型法线贴图。

public class POnlineMapView extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.online_map_activity);
}
}

上面的代码运行良好,表明一切都已正确设置。

我现在正尝试使用 MapView 类来操作中心点等显示设置,但似乎每次尝试获取 GoogleMap 对象时我都获取了一个空对象。为什么会这样?

public class POnlineMapView extends Activity {

private MapView myMapView;
private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myMapView = new MapView(getApplicationContext());
Bundle b = getIntent().getExtras();
double longitude = b.getDouble("longitude");
double latitude = b.getDouble("latitude");

setContentView(R.layout.online_map_activity);
map = myMapView.getMap();

CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude,longitude));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(17);

map.moveCamera(center); //this gives a NullPointerException, probably due to the myMapView.getMap() method?
map.animateCamera(zoom);
}
}

最佳答案

关于android - 谷歌地图 Android API v2 : GoogleMap is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14518024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com