Reputation: 944
I'm using bellow widget,I want to change MyLocation button get to bottom position in my map view
GoogleMap(
onMapCreated: onMapCreated,
options: GoogleMapOptions(
myLocationEnabled :true,
mapType: MapType.hybrid,
cameraPosition: CameraPosition(
target: LatLng(6.8814635,79.8876697),
zoom: 15.0,),
),
),
Upvotes: 19
Views: 30354
Reputation: 361
Just add padding on top! in my case;
padding: EdgeInsets.only(top: 155.0),
Upvotes: -1
Reputation: 503
Use padding property of GoogleMap widget
return Stack(
children: <Widget>[
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
mapType: _currentMapType,
markers: _markers,
onCameraMove: _onCameraMove,
myLocationEnabled: true,
padding: EdgeInsets.only(top: 40.0,),
),
],
);
Upvotes: 23
Reputation: 944
I found the solution. I create FAB button to change My Location button
GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
myLocationEnabled: true,
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _currentLocation,
label: Text('My Location'),
icon: Icon(Icons.location_on),
),
);
}
also, set the _currentLocation
method to call my location
void _currentLocation() async {
final GoogleMapController controller = await _controller.future;
LocationData currentLocation;
var location = new Location();
try {
currentLocation = await location.getLocation();
} on Exception {
currentLocation = null;
}
controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(
bearing: 0,
target: LatLng(currentLocation.latitude, currentLocation.longitude),
zoom: 17.0,
),
));
}
Upvotes: 32