插件的geocoder使用过时版本的Android嵌入



当我运行pub get时,我面临以下错误:

The plugin geocoder uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

GeoCoder包对于较新的flutter版本已弃用。但你可以使用另一种方法。这是兼容较新的扑动版本和完美的工作很好。使用以下选项:https://pub.dev/packages/geocode

使用此方法修复所有错误
https://pub.dev/packages/geocoder2

import 'package:geocoder2/geocoder2.dart';
<<p>得到地址/strong>
FetchGeocoder fetchGeocoder = await Geocoder2.getAddressFromCoordinates(
latitude: 40.714224,
longitude: -73.961452,
googleMapApiKey: "GOOGLE_MAP_API_KEY");
var first = fetchGeocoder.results.first;
print(first.formattedAddress);
<<p>得到坐标/strong>
FetchGeocoder fetchGeocoder = await Geocoder2.getCoordinatesFromAddress(
address: "277 Bedford Ave, Brooklyn, NY 11211, USA",
googleMapApiKey: "GOOGLE_MAP_API_KEY");
var first = fetchGeocoder.results.first;
print("${first.geometry.location.lat} , ${first.geometry.location.lng}");

这是因为最新的flutter更新版本2.5。在我的情况下,我已经通过命令flutter downgrade降级了我的flutter版本,它显示了降级的flutter版本的选项,它解决了我的错误。

您可以使用Geocoding插件来查找地址:

import 'package:geocoding/geocoding.dart';
List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);

这仅仅意味着您想要使用的包已经过时,并且flutter的新更新删除了该包正在使用的一些功能。

快速解决方案:

  • 通过在终端运行'flutter pub outdated'来淘汰flutter,我不建议这样做
  • 或使用此包的替代方案,并确保此替代方案已新升级以与您的flutter版本
  • 兼容

最新更新