插件 `geocoder` 使用已弃用的 Android 嵌入版本

问题描述 投票:0回答:6

当我运行

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.

flutter dart deprecated embedding geocoder
6个回答
3
投票

较新的 flutter 版本已弃用 GeoCoder 包。但您可以使用这种替代方案。这与较新的 flutter 版本兼容并且完美工作。 使用此替代方案:https://pub.dev/packages/geocode


2
投票

用它来修复所有错误
https://pub.dev/packages/geocoder2

import 'package:geocoder2/geocoder2.dart';

获取地址

    FetchGeocoder fetchGeocoder = await Geocoder2.getAddressFromCoordinates(
        latitude: 40.714224,
        longitude: -73.961452,
        googleMapApiKey: "GOOGLE_MAP_API_KEY");
    var first = fetchGeocoder.results.first;
    print(first.formattedAddress);

获取坐标

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}");

1
投票

发生这种情况是因为最新的 flutter 更新版本 2.5。就我而言,我已通过命令

flutter downgrade
降级了我的 flutter 版本,它显示了降级 flutter 版本的选项,并解决了我的错误。


1
投票

您可以使用

Geocoding
插件来查找地址,而不是使用该插件:

import 'package:geocoding/geocoding.dart';

List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);

0
投票

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

快速解决方案:

  • 通过在终端“flutter pub outdated”中运行它来过时颤动,我不推荐
  • 或者使用此包的替代方案,并确保该替代方案是新升级的以与您的 flutter 版本兼容

0
投票

有一个名为 geocoding 的包可以实现相同的功能。请参考一下。

© www.soinside.com 2019 - 2024. All rights reserved.