1

试图将特征批量插入表中。这是我的json

{"features":[{"type":"Feature","geometry":{"type":"Point","coordinates":["-80.358681","27.643045"]},"properties":{"gx_id":"84","address":"9037 Somerset Bay Lane, Vero Beach Port St. Lucie FL 32963","name":"x","phone":"x","email":"x","vehicle":"Cadillac ATS"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.819611","26.380350"]},"properties":{"gx_id":"85","address":"3951 Lakemont Drive, Bonita Springs Fort Meyers FL 34134","name":"x","phone":"x","email":"x","vehicle":"Toyota  Highlander"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-82.677773","27.427950"]},"properties":{"gx_id":"86","address":"6809 Gulf Of Mexico Dr Longboat Key Sarasota FL 34228","name":"x","phone":"x","email":"x","vehicle":"Cadillac  SRX"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-82.677773","27.427950"]},"properties":{"gx_id":"87","address":"6809 Gulf Of Mexico Dr Longboat Key, Sarasota FL 34228","name":"x","phone":"x","email":"x","vehicle":"Cadillac SRX"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.818977","26.590782"]},"properties":{"gx_id":"88","address":"10381 McArthur Palm Lane, Fort Myers Fort Meyers FL 33950","name":"x","phone":"x","email":"x","vehicle":"Infinity M35"}},{"type":"Feature","geometry":{"type":"Point","coordinates":["-81.972443","28.908287"]},"properties":{"gx_id":"89","address":"The Villages, Lake Sumter Landing, Lady Lake Orlando FL 32162","name":"x","phone":"x","email":"x","vehicle":"VW Bettle"}}]}

这是我的阿贾克斯

    function sendBatch(tableID, data){
        dataString = data;
        console.log(dataString);
        var url = "https://www.googleapis.com/mapsengine/v1/tables/"+tableID+"/features/batchInsert";

        jQuery.ajax({
            type: "POST",
            url: url,
            data: dataString,
            contentType: 'application/json',
            headers: {
              'Authorization': 'Bearer ' + authResult.access_token
            },
            success: function(response) {
              // Log the details of the Map.
              console.log(response);
            },
            error: function(response) {
              response = JSON.parse(response.responseText);
              console.log("Error: ", response);
            }
        });
    }

这是我得到的错误

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "The value is invalid.",
    "locationType": "parameter",
    "location": "id"
   }
  ],
  "code": 400,
  "message": "The value is invalid."
 }
}

我正在传递功能,所以我不明白为什么会出现问题。有人有什么想法或想法吗?

4

1 回答 1

1

如果不知道您要发送到 API 的数据/dataString 是什么,则很难判断,但错误显示位置“id”处的“值无效”。您在“id”列中提供的值对于架构不正确的可能性很大。也就是说,如果您设置了一个名为 id 的列,类型为 string,并且您正在发送一个 double(例如),那么您将收到该错误。

需要注意的一件事是,API 要求整数作为带引号的字符串发送,以避免丢失精度。详细信息在文档中。


编辑:我已经成功地设置了一个表格并毫无问题地插入您的 JSON。该错误指向“id”的位置,我认为它对应于您在 URL 中提供的表 ID 。我曾说过它可能是一个特征属性,但该位置看起来像“features[0].properties.id”。该错误还指定了“参数”的“位置类型”。你能检查你的tableID参数并确保它是有效的吗?

于 2014-02-17T10:14:14.517 回答