我使用google_map_flutter在移动应用上创建了地图,但我的应用未显示地图。
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class AgentPosition extends StatefulWidget {
@override
_AgentPositionState createState() => _AgentPositionState();
}
class _AgentPositionState extends State<AgentPosition> {
CameraPosition _initialPosition = CameraPosition(target:
LatLng(7.365302, 12.343439));
Completer<GoogleMapController> _controller = Completer();
void _onMapCreated(GoogleMapController controller) {
_controller.complete(controller);
}
MapType _defaultMapType = MapType.normal;
void _changeMapType(){
setState((){
_defaultMapType = _defaultMapType == MapType.normal ?
MapType.satellite : MapType.normal;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
mapType: _defaultMapType,
myLocationEnabled: true,
onMapCreated: _onMapCreated,
initialCameraPosition: _initialPosition,
),
Container(
margin: EdgeInsets.only(top: 80, right: 10),
alignment: Alignment.topRight,
child: Column(
children: <Widget>[
FloatingActionButton(
child: Icon(Icons.layers),
elevation: 5,
backgroundColor: Colors.teal[200],
onPressed: (){
_changeMapType();
print('Changing the Map Type');
}
)
],
),
)
],
) ,
);
}
}