我想在我的Android应用程序中使用MapView
类显示简单的地图。 我用下面的方法onCreate
在我的活动:Android谷歌地图:地图视图初始化
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
MapsInitializer.initialize(this);
} catch (GooglePlayServicesNotAvailableException e) {
Log.e("Address Map", "Could not initialize google play", e);
}
MapView mapView = new MapView(this);
CameraUpdate camPos = CameraUpdateFactory.newLatLng(new LatLng(11.562276,104.920292));
mapView.getMap().moveCamera(camPos);
setContentView(mapView);
}
我有一个NullPointerException
,因为mapView.getMap()
返回null
的方法。 不明白为什么,Google播放服务显然存在并初始化。
看看这个教程的https: //developers.google.com/maps/documentation/android/v1/hello-mapview – Vivek 2013-02-18 12:15:25