Pau*_*yer 2 google-maps flutter google-maps-flutter
我认为我的问题与这里相同:
Flutter 在 Google 地图小部件中默认显示标记的 infoWindowText
然而,除了指向另一篇文章的链接之外,没有答案,这并不是我想要做的。
当我的地图在我的应用程序中打开时,它会正确显示标记,但我也希望在打开时默认显示所有标签...
正如此处标记之一所示:
我正在创建这样的标记:
for (Location location in _locations) {
final locationMarker = Marker(
markerId: MarkerId(location.id),
position: LatLng(location.geoY, location.geoX),
infoWindow: InfoWindow(
title: location.name,
),
onTap: () => _onTap(location),
icon: _mapMarkers.icon(location.slug),
draggable: false);
markers.add(locationMarker);
}
Run Code Online (Sandbox Code Playgroud)
然后地图是这样的:
Widget _map(Set<Marker> markers) => GoogleMap(
mapType: MapType.normal,
initialCameraPosition: CameraPosition(target: widget.mapCentre),
markers: markers,
...
onMapCreated: (controller) => _onMapCreated(controller, markers),
);
Run Code Online (Sandbox Code Playgroud)
在 _onMapCreated 中,我尝试显示所有标签,但实际上仅显示标记列表中的最后一个:
_onMapCreated(GoogleMapController controller, Set<Marker> markers) {
if (mounted) {
setState(() {
_controller.complete(controller);
controller.setMapStyle(_mapStyle);
for (var marker in markers) {
controller.showMarkerInfoWindow(marker.markerId);
}
});
...
Run Code Online (Sandbox Code Playgroud)
我在用着:
[{
"featureType": "poi",
"stylers": [
{
"visibility": "off"
}
]
}]
Run Code Online (Sandbox Code Playgroud)
从地图上删除兴趣点,我希望我可以做一些类似的事情来默认显示标记标签,但到目前为止我在搜索谷歌时还没有找到任何东西,或者还有另一个解决方案。
小智 5
您可以使用 GoogleMapController 的 showMarkerInfoWindow 属性
final GoogleMapController controller = await _controller.future;
controller.showMarkerInfoWindow(MarkerId('ID_MARKET'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8848 次 |
| 最近记录: |