liodali / osm_flutter

OpenStreetMap plugin for flutter
https://pub.dev/packages/flutter_osm_plugin
MIT License
232 stars 97 forks source link

Problem with onGeoPointClicked #275

Open Alisofin opened 2 years ago

Alisofin commented 2 years ago

Hello, Sometimes, just after the map has been displayed, the onGeoPointClicked method doesn't work, the map doesn't react to any click. You need to leave the page and re-enter to make it work. I haven't found any specific pattern to reproduce it but it happens on 20% of cases, both on simulator and real iOS device. Please help.

liodali commented 2 years ago

you have any log error and if you want to get geopoint when you click on the map use this

controller.listenerMapSingleTapping.addListener(() {
      if (controller.listenerMapSingleTapping.value != null) {
        /// put you logic here
      }
    });

the onGeoPointClicked callback for marker click

Alisofin commented 2 years ago

thanks for your quick answer. In fact, I add markers controller.addMarker(GeoPoint()..) and I detect click on them with onGeoPointClicked. Is it the right thing to do ?

liodali commented 2 years ago

yeah yeah Just for note that in ios side get click marker little different from android I will check it and i will try to fix that

EdoardoVignati commented 2 years ago

Behavior confirmed on iOS. When the map is built for the first time the onGeoPointClicked is never called. I need to change route and back again or hot-reload the app to make it work. Is there any update on this? Thank you!

liodali commented 2 years ago

provide me some example of your widget to see and are you using real iphone or emulator

EdoardoVignati commented 2 years ago

void main() { runApp(const MaterialApp(home: CustomMap())); }

class CustomMap extends StatefulWidget { const CustomMap({Key? key}) : super(key: key);

@override CustomMapState createState() => CustomMapState(); }

class CustomMapState extends State with OSMMixinObserver { late MapController controller;

@override void initState() { super.initState(); controller = MapController( initMapWithUserPosition: false, initPosition: GeoPoint( latitude: 41.889032, longitude: 12.496164, ), )..addObserver(this); }

@override void dispose() { super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar(), body: OrientationBuilder( builder: (ctx, orientation) { return Stack( children: [ OSMFlutter( controller: controller, initZoom: 10, trackMyPosition: false, mapIsLoading: SizedBox.expand( child: Container( color: Colors.black, child: const Center( child: CircularProgressIndicator( color: Colors.white, ), ), ), ), showContributorBadgeForOSM: false, showDefaultInfoWindow: false, markerOption: MarkerOption( defaultMarker: const MarkerIcon( icon: Icon( Icons.location_on, color: Colors.red, size: 100, ), ), ), onGeoPointClicked: (geoPoint) { print("GEOPOINT CLICKED ONLY AFTER HOT-RESTART"); }, ), ], ); }, ), ); }

@override Future mapIsReady(bool isReady) async { Future.delayed(const Duration(seconds: 1), () async { controller.addMarker( GeoPoint(latitude: 41.90691992568336, longitude: 12.456338224647782)); }); } }

EdoardoVignati commented 2 years ago

Any update on this?

liodali commented 2 years ago

i tested with real device (iphone) and I didn't face that problem wierd try to use custon icon for marker i will try to make more investigation on icon clicks

EdoardoVignati commented 2 years ago

I tried with Flutter 3.0.5 and your release 0.39.0 and it's working correctly.