gpt4 book ai didi

Node js Google Routes Library Field Mask(Node js Google Routs库字段掩码)

转载 作者:bug小助手 更新时间:2023-10-25 19:41:14 27 4
gpt4 key购买 nike



I'm trying to use Node Js Google Library the method compute Routes.
But in every execution i try i have:
"catch getPathFromGoogle Error: 3 INVALID_ARGUMENT: FieldMask is a required parameter. See https://cloud.google.com/apis/docs/system-parameters on how to provide it. As an example, you can set the header 'X-Goog-FieldMask' to value 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline' to ask for the route distance, duration, and polyline in the response. You can also set the value to '' in manual testing to get all the available response fields. However, using the '' wildcard is discouraged in production.'"
How can i send this info to this method?

我正在尝试使用Node Js Google库的计算路径方法。但在我尝试的每一次执行中,我都会遇到:“Catch getPath From Google Error:3 INVALID_ARGUMENT:FieldMASK是必需的参数。有关如何提供它,请参阅https://cloud.google.com/apis/docs/system-parameters。例如,您可以将报头‘X-GOOG-FieldMASK’设置为‘routes.DistanceMeters,routes.time,routes.Polyline.encodedPolyline’的值,以请求响应中的路径距离、持续时间和折线。您还可以在手动测试中将该值设置为‘’,以获取所有可用的响应字段。但是,在生产中不鼓励使用‘’通配符。‘“我如何将此信息发送到此方法?


Here is my code:

以下是我的代码:


                r = await routingClient.computeRoutes({
params: {
origin: { lat: origin[1], lng: origin[0] },
destination: {lat: dest[1], lng: dest[0]}
},
timeout: 1000
});

An example of a code working with this method and how put X-Goog-FieldMask would be perfect.

一个使用此方法的代码示例以及如何放置X-GOOG-FieldMask将是完美的。


更多回答
优秀答案推荐

Here's a working example:

下面是一个实用的示例:


import routing from "@googlemaps/routing";
import { GoogleAuth } from "google-auth-library";

const routingClient = new routing.v2.RoutesClient({
authClient: new GoogleAuth().fromAPIKey(
"YOUR_API_KEY"
),
});

async function callComputeRoutes() {
// Run request
const response = await routingClient.computeRoutes(
{
origin: {
address: "Zetland, Sydney, NSW, Australia",
},
destination: {
address: "Coogee Beach, Sydney, NSW, Australia",
},
},
{
otherArgs: {
headers: {
"X-Goog-FieldMask": "*",
},
},
}
);
console.log(response);
}

callComputeRoutes();

I couldn't find this in the docs, couldn't figure this out from the library sources or comments, had to just try and got lucky :)

我在文档中找不到这个,从图书馆的资源或评论中找不到这个,只能试着运气好:)


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com