【问题标题】:Google Places API in FlutterFlutter 中的 Google Places API
【发布时间】:2020-05-20 16:09:54
【问题描述】:

我正在使用 Flutter 开发 Google Places API。我通过引用example 工作。但我得到了谷歌地方 API 类的错误

例如:

未定义的类“GoogleMapsPlaces”。 尝试将名称更改为现有类的名称,或创建一个名称为

的类

我在我的 dart 文件中将flutter_google_places 导入为:

import 'package:flutter_google_places/flutter_google_places.dart'; 但我仍然得到所有类的错误。

使用flutter_google_places 版本0.2.3

【问题讨论】:

  • 导入是否也显示错误?
  • @CopsOnRoad 不,没关系。
  • @CopsOnRoad 不,实际上导入 import 'package:flutter_google_places/flutter_google_places.dart'; 显示为灰色并显示未使用的导入。

标签: flutter dart google-places-api


【解决方案1】:

GoogleMapPlaces 在不同的库中可用,而不是在 flutter_google_places...

https://pub.dev/packages/google_maps_webservice 上可用

【讨论】:

  • 让我看看这个例子
  • 你的代码 sn-p 是这样的:github.com/fluttercommunity/flutter_google_places/blob/master/…,所以我认为这是同样的问题......
  • 正如@HayiNukman 提到的,您需要导入google_maps_webservice packages 才能使用GoogleMapPlaces 类,因为它是从GoogleWebServices 扩展而来的。您导入的包flutter_google_places 用于利用自动完成字段和地点。
【解决方案2】:

你可以为 google place google_place找到另一个包

var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.autocomplete.get("1600 Amphitheatre");

【讨论】:

  • 作为一般规则,您应该描述为什么这个更好,或者甚至为什么您认为这会解决发布者的问题,作为其中的一部分,描述为什么原来的原因可能也是有益的包有特定的问题,否则你的建议似乎是在尝试包之前一直在尝试,直到某些东西起作用。这可能不是您真正希望他们采取的策略。
【解决方案3】:

您需要在 main.dart 中导入 import 'package:google_maps_webservice/places.dart';

【讨论】:

    猜你喜欢
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 2014-03-18
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多