【问题标题】:Extract address Component from Maps picker address从地图选择器地址中提取地址组件
【发布时间】:2021-06-29 11:17:35
【问题描述】:

我已经安装了Google Maps Place Picker

它返回正确的地图,我可以使用地理定位器获得正确的地址。

Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => PlacePicker(
          apiKey: APIKeys.apiKey,   // Put YOUR OWN KEY here.
          onPlacePicked: (result) { 
            print(result.address); 
            Navigator.of(context).pop();
          },
          initialPosition: HomePage.kInitialPosition,
          useCurrentLocation: true,
        ),
      ),
    );

现在这个result 返回 return.addressComponent,它应该是所选地址组件的列表。 我需要在 Map 中获取所有这些值,才能将这些数据推送到 Firestore。 有什么帮助吗?

【问题讨论】:

  • 当您将结果推送到 Firestore 时,您可能需要注意使用 Places API 的应用程序受 Google Maps Platform Terms of Service 的约束,您不能在其中预取、索引、存储或缓存任何内容,但条款中规定的有限条件除外。

标签: flutter google-maps


【解决方案1】:

对象result.addressComponentsList<AddressComponents> 的一种类型,您可以在其中使用for 循环进行迭代。这是一个示例:

Navigator.push(
   context,
   MaterialPageRoute(
      builder: (context) => PlacePicker(
         apiKey:"YOUR_API_KEY", // Put YOUR OWN KEY here.
         onPlacePicked: (result) {
              for (var i in result.addressComponents) {
                  print("Short Name: " +
                         i.shortName +
                        "Long Name: " +
                         i.longName);
              }
              Navigator.of(context).pop();
          },
          initialPosition: _MyHomePageState.kInitialPosition,
          useCurrentLocation: true,
      ),
   ),
);

上面的代码将列出被选中地点的所有shortNamelongName,看起来像这样:

还请注意 @Nelson Jr 的评论,将其推送到您的数据库可能违反了 Google Maps Platform 服务条款。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    相关资源
    最近更新 更多