I am trying to create a screen where the user can put a custom location using plugin flutter_map open street map free
I have tried several solution but they seems outdated every time I try could you help with it ?
my imports
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
Widget build(BuildContext context) {
final MapController mapController = MapController();
List<Marker> markers = []; // List to store markers
void handleTap(TapPosition tapPosition) {
setState(() {
});
}
LatLng tapedlan;
return Scaffold(
appBar: AppBar(title: Text('aaa'),),
body: GestureDetector(
child: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(51.509364, -0.128928),
initialZoom: 3.2,
),
children: [
TileLayer(
additionalOptions: {
'style': 'outdoors',
},
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
MarkerLayer(
markers: markers, // Use the markers list
),
],
mapController: mapController,
),
onTapDown: (TapDownDetails details) => {
},
),
);
}
I have tried this but nothing works
GestureDetector(
child: FlutterMap(
// ... your map configuration
),
onTap: (tapPosition) => {
// Access tappedPosition here
LatLng tappedLatLng = mapController.convertScreenPointToLatLng(tapPosition);
setState(() {
markers.add(
// ... your marker definition
);
});
},
),