gpt4 book ai didi

javascript - 如何更新 Google map 引擎表?

转载 作者:行者123 更新时间:2023-11-30 12:32:34 24 4
gpt4 key购买 nike

我在 Google Maps Engine 中有一个表格,我想在 Google 站点中使用 JavaScript 对其进行动态更新。我发现 this 帮助页面解释了如何将功能附加到现有表,但我正在努力弄清楚如何修改代码,以便它更新表而不是附加到它。我相信我特别需要修改 processResponseprocessErrorResponse 函数。但是,我对 JavaScript/jQuery/JSON 还很陌生,我不确定如何确定我应该用什么来代替 #insert-table-features-response。这里有人可以向我解释一下吗?

编辑:换句话说,我如何使用 JavaScript 发出如下所示的请求?

POST https://www.googleapis.com/mapsengine/v1/tables/{YOUR_TABLE_KEY}/features/batchPatch?key={YOUR_API_KEY}

Content-Type: application/json
Authorization: Bearer {. . .}
X-JavaScript-User-Agent: Google APIs Explorer

{
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
-82,
35
]
},
"properties": {
"Lat": 35,
"Long": -82,
"Name": "6:41:13 AM 11/27/14",
"gx_id": "123ABC456DEF7890"
}
}
]
}

最佳答案

与其尝试将其压缩到对 jpatokal 的回答的评论中,不如将其放入答案中。

正如他们所说,您将希望使用 batchPatch 请求,而不是 batchInsert。在此处查看文档:https://developers.google.com/maps-engine/documentation/reference/v1/tables/features/batchPatch

如果您使用的是文档中提供的 JS,则您链接到的页面上的代码包括此功能:

function insertTableFeatures(tableId) {
doRequest({
path: '/mapsengine/v1/tables/' + tableId + '/features/batchInsert',
method: 'POST',
body: {
features: cities
},
processResponse: function(response) {
$('#insert-table-features-response').text(
JSON.stringify(response, null, 2));
},
processErrorResponse: function(response) {
$('#insert-table-features-response').text('Error response:\n\n' +
JSON.stringify(response, null, 2));
}
});
}

您需要将 pathbatchInsert 更改为 batchPatch 并更新 body: { ... } 。您可以将其替换为您提供的 HTTP 请求的主体,如下所示:

function updateTableFeatures(tableId) {
doRequest({
path: '/mapsengine/v1/tables/' + tableId + '/features/batchPatch',
method: 'POST',
body: {
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
-82,
35
]
},
"properties": {
"Lat": 35,
"Long": -82,
"Name": "6:41:13 AM 11/27/14",
"gx_id": "123ABC456DEF7890"
}
}
]
},
processResponse: function(response) {
// You'll probably want to change these too
$('#insert-table-features-response').text(
JSON.stringify(response, null, 2));
},
processErrorResponse: function(response) {
// You'll probably want to change these too
$('#insert-table-features-response').text('Error response:\n\n' +
JSON.stringify(response, null, 2));
}
});
}

关于javascript - 如何更新 Google map 引擎表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27171292/

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