簡體   English   中英

參數類型&#39;Future<void> Function(TapPosition)&#39; 不能分配給參數類型&#39;void Function(TapPosition, LatLng)?&#39;

[英]The argument type 'Future<void> Function(TapPosition)' can't be assigned to the parameter type 'void Function(TapPosition, LatLng)?'

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
          ),

我正在嘗試在我的顫振應用程序中使用 geocoder2 來處理地圖。 但我正面臨這個錯誤。 如果有人可以提供幫助,那就太好了。

  LatLng point=LatLng(49, -1);

這是我的變量聲明。 現在的錯誤是:

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(

這是我嘗試使用點的錯誤。

onTap回調提供tapPositionpoint

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

包括另一個參數來解決這種情況,如

 onTap: (tapPos, p) async {

更多關於MapOptionsflutter_map/TapCallback

更新

完整的片段就像

  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)),
    );

關於使用包的注意事項

latlong2geocoder2器2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM