tlewis3348
tlewis3348

Reputation: 486

How do I dynamically update a Maps Engine data table with JavaScript?

I have a Maps Engine map with one of the layers linked to a data table containing a single location. I would like to update the data table via JavaScript in Google Sites. The mapsengine.tables.features.batchPatch seems to do what I want, and the help page for the batchInsert version of the same command seems like it could be modified to do what I want. However, I'm having difficulty getting it to work properly. I believe the problem is due to the fact that I don't know what the primary key is for this table or where I can find it (see here for more explanation).

Can anyone here tell me if I'm headed in the right direction, and how I might be able to find this primary key (it also seems to be referred to as a gx_id at times)? Thanks in advance for whatever help you may be able to provide.

Edit: When I go here and get the information on my table, I get the following response:

{
 "tables": [
  {
   "id": {My Table ID},
   "etag": "\"6030101253664097613\"",
   "projectId": {My Project ID},
   "name": "Current Location",
   "description": "",
   "tags": [
   ],
   "writersCanEditPermissions": false,
   "sourceEncoding": "UTF-8",
   "processingStatus": "complete",
   "bbox": [
    -180,
    -90,
    180,
    90
   ],
   "creationTime": "2014-11-11T21:33:43.982Z",
   "lastModifiedTime": "2014-11-12T20:55:20.613Z"
  }
 ]
}

As you can see, there is no gx_id listed. Is there some way to add it, or do I need to recreate the table to be able to add it from the start? If I need to recreate the table, what do I need to do to make sure the gx_id is there, since it wasn't immediately apparent when I created the table last time that anything was missing.

Upvotes: 1

Views: 446

Answers (1)

lambshaanxy
lambshaanxy

Reputation: 23062

Yes, that should work fine. You can find your gx_id simply by fetching a copy of your table and checking the properties. Here's a sample from the docs:

Request:

https://www.googleapis.com/mapsengine/v1/tables/12421761926155747447-06672618218968397709/features?maxResults=500&version=published&key=(YOUR_KEY_HERE)

Response:

{
 "type": "FeatureCollection",
 "features": [
  {
   "type": "Feature",
   "geometry": {
    "type": "Point",
    "coordinates": [
     149.23531999999997,
     -35.352484
    ]
   },
   "properties": {
    ...
    "gx_id": "1" <-- HERE
   }
  },

Upvotes: 1

Related Questions