Home > Software engineering >  The argument type 'Future<void> Function(TapPosition)' can't be assigned to the
The argument type 'Future<void> Function(TapPosition)' can't be assigned to the

Time:07-14

FlutterMap(
            options: MapOptions(
            onTap: (p, point) async {
              GeoData location = await Geocoder2.getDataFromCoordinates(
                  latitude: p.latitude, longitude: p.longitude, googleMapApiKey: '');
              );
            print("${location.country}");
              setState((){
                point=p;
              });
            },
            center: LatLng(49.5, -0.09),
            zoom: 10.0
          ),

I am trying to use geocoder2 in my flutter app to work with maps. But I am facing this error. If someone could help, that'd be great.

  LatLng point=LatLng(49, -1);

This is my declaration of variables. And now the errors are:

The getter 'latitude' isn't defined for the type 'TapPosition'.
The getter 'longitude' isn't defined for the type 'TapPosition'.
A value of type 'TapPosition' can't be assigned to a variable of type 'LatLng'.
                  point: point, builder: (ctx)=> Icon(

This is the error where I am trying to use point.

CodePudding user response:

onTap callback provide tapPosition and point.

typedef TapCallback = void Function(TapPosition tapPosition, LatLng point);

Include another parameters to solve this case like

 onTap: (tapPos, p) async {

More about MapOptions and flutter_map/TapCallback

Update

Full snippet be like

  LatLng point = LatLng(49, -1);
  GeoData? location;
   ...
FlutterMap(
      options: MapOptions(
          onTap: (f, p) async {
            p.latitude;
            location = await Geocoder2.getDataFromCoordinates(
                latitude: p.latitude,
                longitude: p.longitude,
                googleMapApiKey: '');
            setState(() {
              point = p;
            });
          },
          zoom: 10.0,
          center: LatLng(49, -1)),
    );

Note thing about use of packages

latlong2 and geocoder2

  • Related