Reputation: 9295
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.
Upvotes: 9
Views: 7320
Reputation: 59
I use LiteMode programmatically instead of setting attribute of MapView and MapFragment in XML file. Try this:
GoogleMapOptions googleMapOptions = new GoogleMapOptions().liteMode(true);
googleMap.setMapType(googleMapOptions.getMapType());
Or in XML:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mapslastapp.MapsActivity"
map:liteMode="true"
map:cameraZoom="16"
map:mapType="normal"/>
Upvotes: 5
Reputation: 6598
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);
Upvotes: 14