Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

How to display map labels by default with Google Maps Flutter

I think my issue is the same as here:

Flutter show marker's infoWindowText by default in Google map widget

However, there is no answer, except for a link to another post which isn't quite what I want to do.

When my map opens in my app, it shows the markers correctly, but I also want to have all the labels displaying by default on open...

enter image description here

As the shown by one of the markers here:

enter image description here

I'm creating markers like this:

 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);
    }

Then the map like this:

 Widget _map(Set<Marker> markers) => GoogleMap(
        mapType: MapType.normal,
        initialCameraPosition: CameraPosition(target: widget.mapCentre),
        markers: markers,
        ...
        onMapCreated: (controller) => _onMapCreated(controller, markers),
      );

And the in _onMapCreated, I've tried to show all the labels, but only the last in the list of markers is actually displayed:

 _onMapCreated(GoogleMapController controller, Set<Marker> markers) {
    if (mounted) {
      setState(() {
        _controller.complete(controller);
        controller.setMapStyle(_mapStyle);
        for (var marker in markers) {
          controller.showMarkerInfoWindow(marker.markerId);
        }
      });
...

I'm using:

[{
    "featureType": "poi",
    "stylers": [
    {
        "visibility": "off"
    }
    ]
}]

to remove points of interest from the maps and I am hoping I can do something similar to get marker labels to display by default, but so far I've not found anything when searching google, or that there's another solution.

question from:https://stackoverflow.com/questions/65559743/how-to-display-map-labels-by-default-with-google-maps-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...