google-maps - 在谷歌地图标记上添加一个弹出窗口
问题描述
当使用颤振/飞镖单击或点击时,我将如何添加一个弹出窗口以显示有关谷歌地图上特定标记的详细信息。已尝试使用 onTap 功能,但给了我关于如何实现此功能的任何想法
populateHospitals() {
Hospitals = []; //array to obtain individual hospital data
Firestore.instance.collection('markers').getDocuments().then((docs) {
if (docs.documents.isNotEmpty) {
setState(() {
hospitalsToggle = true;
});
for (int i = 0; i < docs.documents.length; ++i) {
Hospitals.add(docs.documents[i].data);
initMarker(docs.documents[i].data);
}
}
});
}
initMarker(hospitals) {
mapController.clearMarkers().then((val) {
mapController.addMarker(MarkerOptions(
position:
LatLng(hospital['location'].latitude, hospital['location'].longitude),// draws the markers of the hospitals
draggable: false, // disables dragging of the marker
consumeTapEvents: true,
infoWindowText: InfoWindowText(hospital['hospitalname'], 'hospital'), //displays the hospitals name when the icon is clicked
));
});
}
解决方案
List <Marker> markers = new List<Marker>();
//Run the loop and add locations to marker
markers.add(
Marker(
markerId: <SOMEID>,
position: LatLng(hospital['location'].latitude, hospital['location'].longitude),
onTap: () {
//this is what you're looking for!
print(hospital['hospitalname']);
}
)
);
//Now add this to your map.
推荐阅读
- postgresql - 是否可以使用 AWS/Glue/Spark shell 写入 RDS raw sql (PostgreSQL)?
- apache-kafka - 如何在 Kafka-Connect 中启用 SASL(在集群内)
- ios - 使用 Firebase 在 iOS 上的密码自动填充/建议
- python - 使用多处理在python3.7中并行运行不同的函数
- java - 在 Java 中有效地拆分大字符串
- c# - [已解决]在无限的 2D 平面上查找点的平铺索引
- python - 包含来自另一个 Visual Studio 项目的 python 类的正确方法是什么?
- delphi - 如何为方法链接的泛型类型获取 TRTTIType
- javascript - 有没有办法像邮递员中的二进制文件一样从画布发送图像?
- amazon-web-services - AWS 上用于微服务的应用程序负载均衡器