Encoding/decoding problem with GPS coordinates


I want to send to TTN the GPS coordinates provided by an Arduino Mega with the Dragino GPS/LORA shield.

In order to encode the GPS coordinates, I use the GitHub - thesolarnomad/lora-serialization: LoraWAN serialization/deserialization library for The Things Network library =>

byte buffer[8];
LoraEncoder encoder(buffer);
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
if (checkGpsFix()) {
// Prepare upstream data transmission at the next possible time.
encoder.writeLatLng(gps.location.lat(), gps.location.lng());
LMIC_setTxData2(1, buffer, sizeof(buffer), 0);
Serial.println(F("Packet queued"));

The code of encoder.writeLatLng is the following (I took a look at the code of the library) =>

void LoraEncoder::writeLatLng(double latitude, double longitude) {
    int32_t lat = latitude * 1e6;
    int32_t lng = longitude * 1e6;

    _intToBytes(_buffer, lat, 4);
    _intToBytes(_buffer + 4, lng, 4);
    _buffer += 8;

The problem is as follows :

On the Arduino side, the Lat, Long (as provided by the TinyGPS++ library - functions gps.location.lat() and gps.location.lng()) are =>

Lat=48.576763 Long=1.941792

On the TTN side, the Lat, Long are =>

"decoded_payload": {
  "decoded": [

The decoder is as follows =>

// js code copied from https://github.com/thesolarnomad/lora-serialization/blob/master/src/decoder.js

function decodeUplink(input) {
var decoded = {};
decoded = latLng(input.bytes.slice(0, 8))

return {
  data: {decoded},
  warnings: [],
  errors: []

So why such a difference between the latitude from the Arduino side and from the TTN side ? The serialization/deserialization of the coordinates (latitude/longitude) is however realized with a precision of 6 decimals (see code above) ?