Flutter 从FireBase检索Flight googlemaps标记
我需要一些帮助,我正在尝试让我的firebase中的所有标记显示在地图上,但是只有一个想要显示!我最终也希望为它添加一个计时方面,但我还没有弄明白:) 所以我主要对从firebase检索感兴趣。但我还想添加一个功能,比如说,它可以在数据库中的条目满10分钟后将其删除 我的代码Flutter 从FireBase检索Flight googlemaps标记,flutter,google-maps,dart,flutter-layout,Flutter,Google Maps,Dart,Flutter Layout,我需要一些帮助,我正在尝试让我的firebase中的所有标记显示在地图上,但是只有一个想要显示!我最终也希望为它添加一个计时方面,但我还没有弄明白:) 所以我主要对从firebase检索感兴趣。但我还想添加一个功能,比如说,它可以在数据库中的条目满10分钟后将其删除 我的代码 import'包:cloud_firestore/cloud_firestore.dart'; 进口“包装:颤振/材料.省道”; 导入“包:google_-maps_-flatter/google_-maps_-flatt
import'包:cloud_firestore/cloud_firestore.dart';
进口“包装:颤振/材料.省道”;
导入“包:google_-maps_-flatter/google_-maps_-flatter.dart”;
类MapsPage扩展StatefulWidget{
@凌驾
_MapsPageState createState()=>\u MapsPageState();
}
类_映射孕态扩展状态{
谷歌地图控制器;
无功电流定位;
地图标记={};
void initMarker(指定,specifyId)异步{
var markerIdVal=specifiyid;
最终MarkerId MarkerId=MarkerId(markerIdVal);
最终标记=标记(
马克里德:马克里德,
位置:LatLng(指定['loc'].纬度,指定['loc'].经度),
infoWindow:infoWindow(标题:'Shop',代码段:指定['name']),
);
设置状态(){
markers[specifiyid]=标记;
});
}
getMarkerData()异步{
FirebaseFirestore.instance.collection('markers').get().then((myMockDoc){
if(myMockDoc.docs.isNotEmpty){
for(int i=0;i
我的终点站
flatter运行键命令。
r热重新加载。
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class MapsPage extends StatefulWidget {
@override
_MapsPageState createState() => _MapsPageState();
}
class _MapsPageState extends State<MapsPage> {
GoogleMapController controller;
var currentLocation;
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
void initMarker(specify, specifyId) async {
var markerIdVal = specifyId;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,
position: LatLng(specify['loc'].latitude, specify['loc'].longitude),
infoWindow: InfoWindow(title: 'Shop', snippet: specify['name']),
);
setState(() {
markers[specifyId] = marker;
});
}
getMarkerData() async {
FirebaseFirestore.instance.collection('markers').get().then((myMockDoc) {
if (myMockDoc.docs.isNotEmpty) {
for (int i = 0; i < myMockDoc.docs.length; i++) {
initMarker(myMockDoc.docs[i].data, myMockDoc.docs[i].id);
}
}
});
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
Set<Marker> getMarker() {
return <Marker>[
Marker(
markerId: MarkerId('markers'),
position: LatLng(43.6500194, -79.3916367),
icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueMagenta),
infoWindow: InfoWindow(title: 'Home'))
].toSet();
}
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 42, 27, 113),
title: Text('Ride!'),
),
body: GoogleMap(
markers: getMarker(),
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: LatLng(43.6500418, -79.3916043), zoom: 13.5),
onMapCreated: (GoogleMapController controller) {
controller = controller;
}));
}
}