import 'package:googleapis/places/v1.dart';
import 'package:googleapis_auth/googleapis_auth.dart';
final http.Client client = clientViaApiKey(apikey);
final PlacesApi places = PlacesApi(client);
GoogleMapsPlacesV1SearchTextResponse res = await places.places.searchText(
GoogleMapsPlacesV1SearchTextRequest(
textQuery: "mcDonals Near Me",
maxResultCount: 10,
locationRestriction:
GoogleMapsPlacesV1SearchTextRequestLocationRestriction.fromJson({
"circle": {
"center": {"latitude": 37.7937, "longitude": -122.3965},
"radius": 500.0
}
}),
),
);
这是我上面的代码! 错误:
DetailedApiRequestError(status: 400, message: FieldMask 是必需参数。有关如何提供它的信息,请参阅 https://cloud.google.com/apis/docs/system-parameters。作为示例,您可以设置标头'X-Goog-FieldMask' 值为 'places.displayName','places.id' 询问地点的显示名称和地点 id 您也可以在手动测试中将值设置为 '*' 以获取所有。可用的响应字段。
您需要添加
$fields
参数(是的,它有一个 $)。通常,您可以将其添加为标题 https://developers.google.com/maps/documentation/places/web-service/text-search
-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel'
但是您也可以将其添加为查询参数:
final fields = "places.id,places.displayName,places.formattedAddress,places.location";
GoogleMapsPlacesV1SearchTextResponse res = await places.places.searchText(
myGoogleMapsPlacesV1SearchTextRequest, $fields: fields);
// you can get all the fields with '*'
res = await places.places.searchText(
myGoogleMapsPlacesV1SearchTextRequest, $fields: '*');
请注意,根据您请求的字段,您将被计费为“基本”、“高级”或“首选”。请参阅账单