参数类型'Future<void>函数(TapPosition) & # 39;不能赋值给参数类型&


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(

这是一个错误,我试图使用点。

onTapcallback提供tapPositionpoint

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

包含另一个参数来解决这种情况,如

onTap: (tapPos, p) async {

关于MapOptions和flutter_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

相关内容

最新更新