2

I'm working with a flutter_map application and I have the map setup with markers and all but I can't figure out how to use the MapEventLongPress class event.

Basically I want to long press the map and get coordinates from the event, anyone willing to help me get in that direction?

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

class MapPage extends StatelessWidget {
  const MapPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return FlutterMap(
      options: MapOptions(center: LatLng(74, 40), minZoom: 10.0),
      layers: [
        TileLayerOptions(
          urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
          subdomains: ['a', 'b', 'c']
        }),
        MarkerLayerOptions(markers: [
          Marker(
            width: 45.0,
            height: 45.0,
            point: LatLng(74, 40),
            builder: (context) => Container(
              child: IconButton(
                icon: Icon(Icons.location_on),
                color: Colors.red,
                iconSize: 45.0,
                onPressed: () async {
                  
                },
              )
            )
          )
        ],
        ),
      ]
    );
  }
}

Theres not much on google on this, I can only find the class documantation at https://pub.dev/documentation/flutter_map/latest/flutter_map.plugin_api/MapEventLongPress-class.html but I could really need some example code to get going.

1 Answers1

0

With the the recent api from flutter_map v3.0.0 you can react to the MapEventLongPress Event like this:

FlutterMap(
    mapController: mapController,
    options: MapOptions(
        ...
        onMapEvent: (evt) {
            if(evt is MapEventLongPress){
                log.d("Hey this a MapEventLongPress event");
                log.d(evt.tapPosition);
            }
        },
        ...
    ),
    children: [...]
)


Sven
  • 1,648
  • 1
  • 21
  • 31