1

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.

Paul Grenyer
  • 1,713
  • 3
  • 30
  • 51
  • What about you provide a [mcve]? What is a "map label" (as in your question title)? What are "marker labels" (as in your question text)? How do you create them? What have you tried so far? etc. – MrUpsidown Jan 04 '21 at 11:47
  • Looks to me like you want a separate `InfoWindow` for each marker, opened by default. That is possible in the Google Maps Javascript API v3 (related questions: [google maps auto open infoWindow](https://stackoverflow.com/questions/43695257/google-maps-auto-open-infowindow), [how to open all infoWIndows with button](https://stackoverflow.com/questions/46906061/how-to-open-all-infowindows-with-button)), but I don't know about flutter. You would be more likely to get a useful answer if you provide a [mcve]. – geocodezip Jan 04 '21 at 12:21
  • Ok, minimal example added. Will also look at API v3. – Paul Grenyer Jan 04 '21 at 20:12
  • As per [github issue](https://github.com/flutter/flutter/issues/19647#issuecomment-574457205), the method `showMarkerInfoWindow();` can only show one info window on the map at a time. – jabamataro Jan 11 '21 at 06:04

1 Answers1

3

You can use showMarkerInfoWindow property the GoogleMapController

final GoogleMapController controller = await _controller.future;
controller.showMarkerInfoWindow(MarkerId('ID_MARKET'));
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Guilherme
  • 31
  • 4