Setting up GoogleMapOptions

I inflate my fragment as follows:

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

and here i have 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 creating a map, do one of the following:

If you use MapFragment, use the MapFragment.newInstance (GoogleMapOptions parameters) static factory method to create the fragment and pass the options to the user configuration.

But I do not understand how I can use this.

+4
source share
2 answers

, GoogleMapOptions , ( MapFragment.newInstance() method - docs). MapFragment xml, . GoogleMap seters UiSettings.

:

GoogleMap googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
+11

LiteMode MapView MapFragment XML. :

GoogleMapOptions googleMapOptions = new GoogleMapOptions().liteMode(true);
googleMap.setMapType(googleMapOptions.getMapType());

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"/>
+1

Source: https://habr.com/ru/post/1529203/


All Articles