[英]How to consume Google map web services API in my flutter APP
我是 Flutter 的新手,我非常了解将 Google 地图 API 用于原生 Android 应用程序。 但是,在我的 flutter 应用程序中,我需要 Google Places 搜索自动完成。 我遇到了一个名为google_maps_webservice的插件,它使用谷歌地图 API,例如使用谷歌网络服务的方向、地点和地理编码。 我的问题是在为 google maps API 设置网络服务方面缺乏理解和经验,我如何在我的 flutter 应用程序中使用该插件? 例如,如果我必须在 android 中使用Places API,我会在云控制台中启用Goole Places SDK并为 Android App 生成一个 API 限制。 但是对于 Flutter,Android 和 iOS 都将使用来自 Web API 调用的相同服务。 我该怎么办? 现在我没有后端知识来设置要在从控制台创建 API 时使用的域。
您可以导入 google_maps_webservices 包
import 'package:google_maps_webservice/places.dart';
并在您的代码中使用它:
final places = GoogleMapsPlaces('<Your-API-Key>');
final response = await places.autocomplete('<What-you-are-searching-for>');
if (response.isOkay) {
for (Prediction prediction in response.predictions) {
print(prediction.description);
}
}
一些注意事项:
1. 确保您使用的是 Web API 密钥
2. 确保在 Cloud Console 中激活 Google Places SDK。
3. 为避免收到OVER_QUERY_LIMIT
status
消息,请确保您使用的是计费帐户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.