Changing Map Options

The options parameter allows us to set some default settings like enabling/disabling gestures or setting the default camera position, etc.

Changing map type

We can set the map type using the mapType parameter in GoogleMapOptions .

This can be set to satellite, hybrid, normal or terrain.

GoogleMap(

onMapCreated: (GoogleMapController controller) {},

options: GoogleMapOptions(

mapType: MapType.satellite,

),

),

Switching to satellite view

Set default camera position

Setting the cameraPosition parameter sets the default camera position to a target. We will look at this in detail when we look at CameraPosition in the next section.

options: GoogleMapOptions(

cameraPosition: CameraPosition(

target: LatLng(37.4219999, -122.0862462),

),

),

Showing user location

The user’s location can be shown on the map by setting the myLocationEnabled parameter to true. For this to work we must also add the required permissions on both platforms.

On Android:

Add

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />

or

<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” />

to manifest.xml . We also need to explicitly ask the user for permission.

For this, a package like permission_handler can be used to achieve this.

On iOS:

Add a ‘ NSLocationWhenInUseUsageDescription ’ key to your ‘ Info.plist ’ file. This will automatically prompt the user for permissions when the map tries to turn on the My Location layer.

The user’s location is now displayed

If all goes well, this should be the result.

Enabling/Disabling Gestures

GoogleMapOptions gives us various options to either enable or disable specific types of gestures like tilt, zoom, etc.

options: GoogleMapOptions(

cameraPosition: CameraPosition(

target: LatLng(37.4219999, -122.0862462),

),

rotateGesturesEnabled: false,

scrollGesturesEnabled: false,

tiltGesturesEnabled: false,

)

This code snippet disables the three gestures mentioned.