【发布时间】:2020-03-31 01:43:52
【问题描述】:
我正在尝试在 firestore 的地图上显示标记,并且我使用了谷歌地图颤振插件,但标记没有显示在地图上。我试图在模拟器和 Android 手机上运行该应用程序。 请帮忙。
这是代码:
@override
void initState() {
super.initState();
populateClients();
Geolocator().getCurrentPosition().then((currloc) {
setState(() {
currentLocation = currloc;
});
});
}
populateClients() async {
var pos = await Geolocator().getCurrentPosition();
final coordinates = new coder.Coordinates(
pos.latitude, pos.longitude);
var addresses = await coder.Geocoder.local.findAddressesFromCoordinates(
coordinates);
var first = addresses.first;
initializeDateFormatting();
var format = DateFormat.d('ar');
var dateString = format.format(DateTime.now());
final FirebaseUser user = await _auth.currentUser();
final uid = user.uid;
Firestore.instance.collection('profiles')
.where('City', isEqualTo: first.locality)
.where('Days', arrayContains: dateString)
.where('Uid' != uid)
.where('role' == 'user')
.getDocuments().then((docs) {
if (docs.documents.isNotEmpty) {
for (int i = 0; i < docs.documents.length; i++) {
clients.add(docs.documents[i].data);
initMarker(docs.documents[i].data,
docs.documents[i].documentID);
}
}
});
}
void initMarker(client, markerRef) {
var markerIdVal = markerRef;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,
position: LatLng(double.parse(client['Location'].latitude),
double.parse(client['Location'].longitude)),
infoWindow: InfoWindow(title: "click here", snippet: "click to show the details"),
icon: BitmapDescriptor.defaultMarker,
onTap: () {
showAlertDialog(client);
}
);
setState(() {
// adding a new marker to map
markers[markerId] = marker;
});
}
代码有什么错误?
【问题讨论】:
标签: google-maps flutter dart