Firebase LatLng don';不要出现在地图上

Firebase LatLng don';不要出现在地图上,firebase,google-maps,flutter,dart,google-maps-flutter,Firebase,Google Maps,Flutter,Dart,Google Maps Flutter,我正试图在谷歌地图上添加firebase的一些标记,但我不明白为什么这些标记没有出现在谷歌地图上(在用户界面上)。有人能帮我或建议我更新教程吗 void main() => runApp(Parkings()); class Parkings extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: '...',

我正试图在谷歌地图上添加firebase的一些标记,但我不明白为什么这些标记没有出现在谷歌地图上(在用户界面上)。有人能帮我或建议我更新教程吗

void main() => runApp(Parkings());

class Parkings extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '...',
      home: MapSample(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MapSample extends StatefulWidget {
  @override
  State<MapSample> createState() => MapSampleState();
}

class MapSampleState extends State<MapSample> {
  final FirebaseFirestore _database = FirebaseFirestore.instance;
  Completer<GoogleMapController> _controller = Completer();
  Map<MarkerId, Marker> markers = <MarkerId, Marker>{};

  void _changeMap(LatLng position) async {
    final GoogleMapController controller = await _controller.future;

    controller.animateCamera(CameraUpdate.newCameraPosition(
      CameraPosition(
        bearing: 0,
        target: LatLng(position.latitude, position.longitude),
        zoom: 20.0,
      ),
    ));
  }

  @override
  void initState() {
    addParkings();
    super.initState();
  }

纬度和经度在Firestore中保存为字符串,而不是双精度字符串

//创建新标记
最终标记=标记(
马克里德:马克里德,
位置:LatLng(double.parse(parking['Latitud']),double.parse(parking['Longitud']),//字符串到double
信息窗口:信息窗口(标题:停车['name']),
);

更好的方法是使用Firestore软件包中的
GeoPoint
类来完成您尝试执行的操作。

纬度和经度在Firestore中保存为字符串,而不是双精度字符串

If anyone needs a flutter application that shows markers (from firebase) on map here is an example: 
//创建新标记
最终标记=标记(
马克里德:马克里德,
位置:LatLng(double.parse(parking['Latitud']),double.parse(parking['Longitud']),//字符串到double
信息窗口:信息窗口(标题:停车['name']),
);
更好的方法是使用Firestore软件包中的
GeoPoint
类来完成您要做的事情

If anyone needs a flutter application that shows markers (from firebase) on map here is an example: 
map.dart:

    class StoreMap extends StatelessWidget {
      StoreMap({
        Key key,
        @required this.documents,
        @required this.initialPosition,
      }) : super(key: key);
    
      
      final List<DocumentSnapshot> documents;
      final LatLng initialPosition;
      final Completer<GoogleMapController> _controller = Completer();
    
    
      static final CameraPosition _initialPosition = CameraPosition(
        target: LatLng(45.791789, 24.150390),
        zoom: 14,
      );
    
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: GoogleMap(
            mapType: MapType.hybrid,
            initialCameraPosition: _initialPosition,
            onMapCreated: (GoogleMapController controller) {
              _controller.complete(controller);
            },
            myLocationEnabled: true,
            markers: documents
                .map((document) => Marker(
                      markerId: MarkerId(document.get('name')),
                      position: LatLng(
                        document.get('location').latitude,
                        document.get('location').longitude,
                      ),
                      infoWindow: InfoWindow(
                          title: document.get('name'),
                 ),
                    )
                .toSet(),
          ),
      floatingActionButton: FloatingActionButton(
            onPressed: _currentLocation,
            child: Icon(Icons.location_searching),
          ),
        );
      }
    
       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: 18.0,
          ),
        ));
      }
    
   
class StoreMap扩展了无状态小部件{
商店地图({
关键点,
@需要本文件,
@需要这个初始位置,
}):super(key:key);
最后文件清单;
最终车床初始位置;
最终完成者_控制器=完成者();
静态最终摄像机位置_initialPosition=摄像机位置(
目标:拉丁美洲(45.791789,24.150390),
缩放:14,
);
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:谷歌地图(
mapType:mapType.hybrid,
initialCameraPosition:\u initialPosition,
onMapCreated:(谷歌地图控制器){
_控制器。完成(控制器);
},
myLocationEnabled:对,
标记:文件
.map((文档)=>标记(
markerId:markerId(document.get('name')),
职位:LatLng(
document.get('location')。纬度,
document.get('location')。经度,
),
信息窗口:信息窗口(
标题:document.get('name'),
),
)
.toSet(),
),
浮动操作按钮:浮动操作按钮(
onPressed:\u当前位置,
子:图标(图标。位置搜索),
),
);
}
void\u currentLocation()异步{
最终GoogleMapController=wait_controller.future;
位置数据当前位置;
var location=新位置();
试一试{
currentLocation=等待位置。getLocation();
}例外{
currentLocation=null;
}
controller.animateCamera(CameraUpdate.newCameraPosition(
摄像定位(
方位:0,,
目标:LatLng(currentLocation.latitude,currentLocation.longitude),
缩放:18.0,
),
));
}
home.dart:

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Stream<QuerySnapshot> _parkingsDb;
  List<Marker> allMarkers = [];

  @override
  void initState() {
    super.initState();
    // ignore: deprecated_member_use
    _parkingsDb = Firestore.instance.collection('places').snapshots();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: new Text('....'), 
          backgroundColor: Colors.Blue,
        ),
        body: StreamBuilder<QuerySnapshot>(
          stream: _parkingsDb,
          builder: (context, snapshot) {
            if (snapshot.hasError) {
              return Center(child: Text('Error: ${snapshot.error}'));
            }
            if (!snapshot.hasData) {
              return Center(child: const Text('Loading...'));
            }

            // ignore: deprecated_member_use
            return StoreMap(
                // ignore: deprecated_member_use
                documents: snapshot.data.documents,
                initialPosition: const LatLng(45.791789, 24.150390));
          },
        ));
  }
}

class StoreList extends StatelessWidget {
  const StoreList({
    Key key,
    @required this.documents,
  }) : super(key: key);
  final List<DocumentSnapshot> documents;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: documents.length,
        itemBuilder: (builder, index) {
          final document = documents[index];
          return ListTile(
            title: Text(document.get('name')),
            subtitle: Text(document.get('location').toString()),
          );
        });
  }
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
溪流公园数据库;
列出所有标记=[];
@凌驾
void initState(){
super.initState();
//忽略:不推荐的\u成员\u使用
_parkingsDb=Firestore.instance.collection('places').snapshots();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:新的appBar(
标题:新文本(“…”),
背景颜色:颜色。蓝色,
),
正文:StreamBuilder(
溪流:_parkingsDb,
生成器:(上下文,快照){
if(snapshot.hasError){
返回中心(子项:Text('Error:${snapshot.Error}');
}
如果(!snapshot.hasData){
返回中心(子项:常量文本('Loading…');
}
//忽略:不推荐的\u成员\u使用
返回商店地图(
//忽略:不推荐的\u成员\u使用
文档:snapshot.data.documents,
初始位置:const LatLng(45.791789,24.150390));
},
));
}
}
类StoreList扩展了无状态小部件{
常数存储列表({
关键点,
@需要本文件,
}):super(key:key);
最后文件清单;
@凌驾
小部件构建(构建上下文){
返回ListView.builder(
itemCount:documents.length,
itemBuilder:(生成器,索引){
最终文件=文件[索引];
返回列表块(
标题:文本(document.get('name')),
字幕:文本(document.get('location').toString()),
);
});
}
}
请记住,我是初学者,我不知道这里是否有重大错误:)

map.dart:

    class StoreMap extends StatelessWidget {
      StoreMap({
        Key key,
        @required this.documents,
        @required this.initialPosition,
      }) : super(key: key);
    
      
      final List<DocumentSnapshot> documents;
      final LatLng initialPosition;
      final Completer<GoogleMapController> _controller = Completer();
    
    
      static final CameraPosition _initialPosition = CameraPosition(
        target: LatLng(45.791789, 24.150390),
        zoom: 14,
      );
    
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: GoogleMap(
            mapType: MapType.hybrid,
            initialCameraPosition: _initialPosition,
            onMapCreated: (GoogleMapController controller) {
              _controller.complete(controller);
            },
            myLocationEnabled: true,
            markers: documents
                .map((document) => Marker(
                      markerId: MarkerId(document.get('name')),
                      position: LatLng(
                        document.get('location').latitude,
                        document.get('location').longitude,
                      ),
                      infoWindow: InfoWindow(
                          title: document.get('name'),
                 ),
                    )
                .toSet(),
          ),
      floatingActionButton: FloatingActionButton(
            onPressed: _currentLocation,
            child: Icon(Icons.location_searching),
          ),
        );
      }
    
       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: 18.0,
          ),
        ));
      }
    
   
class StoreMap扩展了无状态小部件{
商店地图({
关键点,
@需要本文件,
@需要这个初始位置,
}):super(key:key);
最后文件清单;
最终车床初始位置;
最终完成者_控制器=完成者();
静态最终摄像机位置_initialPosition=摄像机位置(
目标:拉丁美洲(45.791789,24.150390),
缩放:14,
);
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:谷歌地图(
mapType:mapType.hybrid,
initialCameraPosition:\u initialPosition,
onmacreated:(G)
class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Stream<QuerySnapshot> _parkingsDb;
  List<Marker> allMarkers = [];

  @override
  void initState() {
    super.initState();
    // ignore: deprecated_member_use
    _parkingsDb = Firestore.instance.collection('places').snapshots();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: new Text('....'), 
          backgroundColor: Colors.Blue,
        ),
        body: StreamBuilder<QuerySnapshot>(
          stream: _parkingsDb,
          builder: (context, snapshot) {
            if (snapshot.hasError) {
              return Center(child: Text('Error: ${snapshot.error}'));
            }
            if (!snapshot.hasData) {
              return Center(child: const Text('Loading...'));
            }

            // ignore: deprecated_member_use
            return StoreMap(
                // ignore: deprecated_member_use
                documents: snapshot.data.documents,
                initialPosition: const LatLng(45.791789, 24.150390));
          },
        ));
  }
}

class StoreList extends StatelessWidget {
  const StoreList({
    Key key,
    @required this.documents,
  }) : super(key: key);
  final List<DocumentSnapshot> documents;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: documents.length,
        itemBuilder: (builder, index) {
          final document = documents[index];
          return ListTile(
            title: Text(document.get('name')),
            subtitle: Text(document.get('location').toString()),
          );
        });
  }
}