Creating location from lat and lng

Hello everyone,

I want to build the tag location, to use for GPS.

I have 2 values sent from the device, lat and lng.

How do I combine them to make the location tag?

Thank you

const payload_raw = payload.find(x => x.variable === ‘payload_raw’ || x.variable === ‘payload’ || x.variable === ‘data’);

if (payload_raw) {

try {

// Convert the data from Hex to Javascript Buffer.

const buffer = Buffer.from(payload\_raw.value, 'hex');




const data = \[

  { variable: 'Timestamp',  value: Date(buffer.readUInt32BE(3)).toLocaleString() },

  { variable: 'latitude',  value: buffer.readInt32BE(7) / 1000000 },

  { variable: 'longitude',  value: buffer.readInt32BE(11) / 1000000 },

  { variable: 'speed',  value: buffer.readInt8(15), unit: 'mph' },

  { variable: 'Angle',  value: buffer.readInt16BE(16) , unit: 'C' },

  { variable: 'Altitude',  value: buffer.readUInt16BE(18) },

  { variable: 'Electricity',  value: buffer.readInt8(22), unit: '%' },

  { variable: 'Altitude',  value: buffer.readUInt16BE(18) },

\];





// This will concat the content sent by your device with the content generated in this payload parser.

// It also adds the field "serie" and "time" to it, copying from your sensor data.

payload = payload.concat(data.map(x => ({ ...x, serie: payload\_raw.serie, time: payload\_raw.time })));

} catch (e) {

// Print the error to the Live Inspector.

console.error(e);



// Return the variable parse\_error for debugging.

payload = \[{ variable: 'parse\_error', value: e.message }\];

}

console.log(device)

}

Hi Roberto,

A location variable must contain an object called ‘location’ with lat and lng inside, e.g:

{

variable: 'location',  

value: '26.199906, -80.141655',  

location: {  

    lat: 26.199906,  

    lng: \-80.141655

}

}

I updated your parser:

const payload_raw = payload.find(x => x.variable === 'payload_raw' || x.variable === 'payload' || x.variable === 'data');if (payload_raw) {  try {    // Convert the data from Hex to Javascript Buffer.    const buffer = Buffer.from(payload_raw.value, 'hex');const lng = buffer.readInt32BE(11) / 1000000;         const lat = buffer.readInt32BE(7) / 1000000;    const data = [      { variable: 'Timestamp',  value: Date(buffer.readUInt32BE(3)).toLocaleString() },      { variable: 'location',  value: `${lat}, ${lng}`, location: { lat, lng } },      { variable: 'speed',  value: buffer.readInt8(15), unit: 'mph' },      { variable: 'Angle',  value: buffer.readInt16BE(16) , unit: 'C' },      { variable: 'Altitude',  value: buffer.readUInt16BE(18) },      { variable: 'Electricity',  value: buffer.readInt8(22), unit: '%' },      { variable: 'Altitude',  value: buffer.readUInt16BE(18) },    ];    // This will concat the content sent by your device with the content generated in this payload parser.    // It also adds the field "serie" and "time" to it, copying from your sensor data.    payload = payload.concat(data.map(x => ({ ...x, serie: payload_raw.serie, time: payload_raw.time })));  } catch (e) {    // Print the error to the Live Inspector.    console.error(e);    // Return the variable parse_error for debugging.    payload = [{ variable: 'parse_error', value: e.message }];  }  console.log(device)}