Search code examples
reactjscompressionglympse

Format for sending location data in body


I'm coding in React-Native.

Glympse docs says that location data should be sent in a delta-compressed array. I don't really know what that means. I think I get the idea of each element being the amount of change (delta) from the previous element, but I still don't have a clear picture of how the body should look when I make the POST request.

Can anyone show an example of this process?


Solution

  • Examples of location arrays that are compressed can be found here https://developer.glympse.com/docs/core/api/reference/objects/location-points#examples

    The idea behind this format is that the first item in the array contains specific values for each parameter, but each item that comes after that only contains the change (or delta) from the previous point.

    [
      [1339989715000, 37123450, -112123450, 18000, 55, null, 2, 4],
      [1000, 1000000, 1000000, 0, null, 1000, 1, -1],
      [1000, 0, 0, 0, 1, 0, 0, 0],
      [1000, 0, 0, 0, 0, 0, 0, 0],
      [1000, 0, 0, 0, 0, 0, 0, 0]
    ]
    

    The first parameter is the timestamp, so if we look at the second item it shows 1000 which means it's the first timestamp + 1000ms.

    The second parameter is latitude * 10^6. The first item shows latitude 37.123450, and the second item in the array has the value 1000000 which represents 37123450 + 1000000 or the latitude 38.123450. Not likely to have something moving that fast in real data, but that's the idea of how this format works.

    Timestamp, latitude, and longitude are the only required fields. A POST body with only the required fields would look like this.

    [
      [1339989715000, 37123450, -112123450],
      [1000, 1000000, 1000000],
      [1000, 0, 0],
      [1000, 0, 0],
    ]