Android programmatically created by MapView v2 not showing

I updated RawMapViewDemoActivity.java in the Google Maps v2 application for Android to programmatically create a MapView, but the map does not appear. I just get a blank screen.

I replaced

mMapView = (MapView) findViewById(R.id.map); 

from

  GoogleMapOptions options = new GoogleMapOptions(); options.camera(new CameraPosition(new LatLng(0, 0), 15, 0, 0)); mMapView = new MapView(this, options); mMapView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 

What am I doing wrong?

+6
source share
2 answers

Have all livecycle methods migrated to the new MapView ?

 mMapView.onCreate(savedInstanceState); 

See API Reference

+2
source

Sorry, I fixed this a while ago, but forgot to post the answer.

It seems that MapView should be placed in the layout container before it displays correctly. The following snippet shows what I did to make the sample work.

 LinearLayout linearLayout = new LinearLayout(this); GoogleMapOptions options = new GoogleMapOptions(); options.camera(new CameraPosition(new LatLng(0, 0), 1, 0, 0)); mMapView = new MapView(this, options); linearLayout.addView(mMapView); setContentView(linearLayout); 
+1
source

All Articles