I updated RawMapViewDemoActivity.java in the Android Google Maps v2 sample app to programmatically create a MapView but map is not displayed. I just get a blank screen.
I replaced
mMapView = (MapView) findViewById(R.id.map);
with
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?
Have you forwarded all the livecycle methods to the new MapView
?
mMapView.onCreate(savedInstanceState);
Take a look at the API Reference
Sorry - I fixed this a while ago, but forgot to post the answer.
It seems that a MapView must be placed in a layout container before it will be correctly displayed. 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With