我想在我的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