Javascript 如何更新Google地图引擎表?
我在谷歌地图引擎中有一个表,我想在谷歌网站上用JavaScript动态更新它。我找到了一个帮助页面,该页面解释了如何将特性附加到现有表中,但我正在努力找出如何修改代码,使其更新表而不是附加到表中。我认为我特别需要修改Javascript 如何更新Google地图引擎表?,javascript,google-maps-engine,Javascript,Google Maps Engine,我在谷歌地图引擎中有一个表,我想在谷歌网站上用JavaScript动态更新它。我找到了一个帮助页面,该页面解释了如何将特性附加到现有表中,但我正在努力找出如何修改代码,使其更新表而不是附加到表中。我认为我特别需要修改processResponse和processErrorResponse函数。然而,我对JavaScript/jQuery/JSON相当陌生,我不确定如何确定我应该拥有什么而不是#insert table features response。这里有人能向我解释吗 编辑:换一种说法,我
processResponse
和processErrorResponse
函数。然而,我对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"
}
}
]
}
batchInsert
,与名称相同,仅插入新功能。试试看。与其试着把这句话塞进对jpatokal答案的评论中,我会把它放在一个答案中
正如他们所说,您将希望使用batchPatch
请求,而不是batchInsert
。请在此处查看文档:
如果您使用的是文档中提供的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));
}
});
}
您需要将路径
从batchInsert
更改为batchPatch
,并更新正文:{…}
。您可以将其替换为您提供的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));
}
});
}
对不起,我想我没说清楚。我知道我需要使用
batchPatch
(我用API explorer设置了所有请求),但我不知道如何修改batchInsert
帮助页面上显示的JavaScript来执行我想要的请求,而不是显示的请求。我将尝试修改这个问题,使之更清楚。