Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting GoogleMapOptions programmatically

I am inflating my fragment like this:

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.MapFragment_map_Fragment)).getMap(); 

and here I have my options:

GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);

In the documentation I see that I need to use this:

To apply these options when you are creating a map, do one of the following:

If you are using a MapFragment, use the MapFragment.newInstance(GoogleMapOptions options) static factory method to construct the fragment and pass in your custom configured options.

But I don't understand how am I suppose to use this.

like image 575
vlio20 Avatar asked Feb 27 '14 12:02

vlio20


1 Answers

I think you can use GoogleMapOptions only if you are creating map view programmatically(passing options to MapFragment.newInstance() method - docs). You are inflating MapFragment from xml so you wont be able to use them in that way. In your case you can still change map options by using GoogleMap setters or UiSettings.

For example:

GoogleMap googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
like image 90
Leszek Avatar answered Sep 26 '22 09:09

Leszek