# Location and GPS

## Create a Database Field

We need to create a Database Field that stores the Location on your Datacake Device. Add a new field an select the Type "Geo Location":

![](/files/-MFvaSXhX64wzaEr7fH4)

## Decode Location Data

In order to be able to record location data into a field on your Datacake device, you need to format the location data according to the format required by Datacake.

In the following example, we assume that your device is forwarding the location as two separate measurement values - latitude and longitude.

```javascript
function Decoder(bytes, port) {
    var lat = (bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3]) / 1000000;
    var lon = (bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7]) / 1000000;   
    
    return ...
}
```

Datacake requires Location to be send as a joined data package.&#x20;

```javascript
var value = "(" + lat + "," + lon + ")"
// value = "(5.235262,21.9399536)"
```

In a complete example, this will look like the following:

```javascript
function Decoder(bytes, port) {

    var datacakeFields = [];

    var lat = (bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3]) / 1000000;
    var lon = (bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7]) / 1000000;

    datacakeFields.push({
        field: "LOCATION",
        value: "(" + lat + "," + lon + ")"
    });
    
    return datacakeFields;
}
```

Note: The above example how to parse the bytes into Latitude and Longitude is taken from the Dragino LGT92 LoRaWAN Tracker.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datacake.de/lorawan/payload-decoders/location-and-gps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
