Flutter腹板:如何使用谷歌的地方自动完成在Flutter网页?

jei2mxaa  于 2023-01-27  发布在  Flutter
关注(0)|答案(1)|浏览(161)

我用了几乎每一个软件包的地方自动完成,我得到交叉错误。请让我知道,如果有任何方法来使用地方自动完成在Android,iOS和网络一起。

var p = await PlacesAutocomplete.show(
    radius: 500000,
    strictbounds: false,
    region: "in",
    language: "en",
    context: context,
    mode: Mode.overlay,
    apiKey: "key",
    components: [new Component(Component.country, "in")],
    types: ["(cities)"],
    hint: "Search City",
);

目前我正在使用此函数

8ehkhllq

8ehkhllq1#

要在Flutter Web应用程序中使用Google Places Autocomplete API,您需要执行以下步骤:
注册Google Cloud Platform帐户并启用Places API。在Google Cloud Console中创建新项目,并生成API密钥。将google_maps_webservice包添加到pubspec.yaml文件中Flutter项目的依赖项。导入该包并使用GoogleMapsPlaces类向Places API发出请求。以下是如何在Flutter Web应用程序中使用自动完成功能的示例:

import 'package:flutter/material.dart';
import 'package:google_maps_webservice/places.dart';

class PlacesAutocompletePage extends StatefulWidget {
  @override
  _PlacesAutocompletePageState createState() => _PlacesAutocompletePageState();
}

class _PlacesAutocompletePageState extends State<PlacesAutocompletePage> {
  final _placesAutocomplete = GoogleMapsPlaces(apiKey: 'YOUR_API_KEY');
  String _placeId;

  Future<void> _getPlacePredictions() async {
    final predictions = await _placesAutocomplete.autocomplete(
      input: 'Google',
    );

    for (final prediction in predictions.predictions) {
      print(prediction.description);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Places Autocomplete'),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: _getPlacePredictions,
          child: Text('Get Place Predictions'),
        ),
      ),
    );
  }
}

相关问题