Can i run an automated parser to a message?

I’m trying to create an automation to open maps through coordinates but the coordinates are Parsed from NMEA GPS Format.I receive that kind of Format through SMS Message from a specific contact (It’s the only kind of message I will receive from that contact) it runs a javascript code to parse and give me the coordinates (latitude & longitude)

That’s the message I’d always get

$GPRMC,152803.00,A,3016.57522,N,03720.57277,E,0.478,,261224,,,A*71
$GPVTG,,T,,M,0.478,N,0.885,K,A*2D
$GPGGA,115803.00,3016.57522,N,03720.57277,E,1,05,2.99,47.3,M,15.4,M,,*60
$GPGSA,A,3,28,29,05,25,12,,,,,,,,3.79,2.99,2.33*0F
$GPGSV,3,1,11,05,20,120,19,11,32,045,20,12,52,083,23,12,22,204,19*7C
$GPGSV,3,2,11,20,24,082,09,24,22,172,,25,66,354,29,28,26,311,23*7F
$GPGSV,3,3,11,29,54,292,33,31,03,323,,32,05,263,*4A
$GPGLL,3016.57522,N,03720.57277,E,152803.00,A,A*62

That’s the JS code I run to get an output but its blank

var messageBody = input;

var lines = messageBody.split('\n');

// Function to convert DDM to decimal degrees
function convertDDMToDD(ddm, hemisphere) {
    var degrees = Math.floor(ddm / 100);
    var minutes = ddm % 100;
    var dd = degrees + (minutes / 60);
    if (hemisphere === 'S' || hemisphere === 'W') {
        dd = -dd;
    }
    return dd.toFixed(6); 
}

var latitude, longitude;

// Loop through each line to find the GPRMC sentence
for (var i = 0; i < lines.length; i++) {
    var line = lines[i];
    if (line.startsWith('$GPRMC')) {
        var parts = line.split(',');
        if (parts.length >= 10 && parts[2] === 'A') { // Check for valid data
            // Extract latitude, longitude, and hemisphere indicators
            var latDDM = parseFloat(parts[3]);
            var latHemi = parts[4];
            var lonDDM = parseFloat(parts[5]);
            var lonHemi = parts[6];
            // Convert to decimal degrees
            latitude = convertDDMToDD(latDDM, latHemi);
            longitude = convertDDMToDD(lonDDM, lonHemi);
            var result = "https://maps.apple.com/maps?q=" + latitude + ',' + longitude;
            completion(result);
        }
    }
}

If I put the input in and change the completion() funcion to say a console.log()

var messageBody = `$GPRMC,152803.00,A,3016.57522,N,03720.57277,E,0.478,,261224,,,A*71
$GPVTG,,T,,M,0.478,N,0.885,K,A*2D
$GPGGA,115803.00,3016.57522,N,03720.57277,E,1,05,2.99,47.3,M,15.4,M,,*60
$GPGSA,A,3,28,29,05,25,12,,,,,,,,3.79,2.99,2.33*0F
$GPGSV,3,1,11,05,20,120,19,11,32,045,20,12,52,083,23,12,22,204,19*7C
$GPGSV,3,2,11,20,24,082,09,24,22,172,,25,66,354,29,28,26,311,23*7F
$GPGSV,3,3,11,29,54,292,33,31,03,323,,32,05,263,*4A
$GPGLL,3016.57522,N,03720.57277,E,152803.00,A,A*62`;

var lines = messageBody.split('\n');

// Function to convert DDM to decimal degrees
function convertDDMToDD(ddm, hemisphere) {
    var degrees = Math.floor(ddm / 100);
    var minutes = ddm % 100;
    var dd = degrees + (minutes / 60);
    if (hemisphere === 'S' || hemisphere === 'W') {
        dd = -dd;
    }
    return dd.toFixed(6); 
}

var latitude, longitude;

// Loop through each line to find the GPRMC sentence
for (var i = 0; i < lines.length; i++) {
    var line = lines[i];
    if (line.startsWith('$GPRMC')) {
        var parts = line.split(',');
        if (parts.length >= 10 && parts[2] === 'A') { // Check for valid data
            // Extract latitude, longitude, and hemisphere indicators
            var latDDM = parseFloat(parts[3]);
            var latHemi = parts[4];
            var lonDDM = parseFloat(parts[5]);
            var lonHemi = parts[6];
            // Convert to decimal degrees
            latitude = convertDDMToDD(latDDM, latHemi);
            longitude = convertDDMToDD(lonDDM, lonHemi);
            var result = "https://maps.apple.com/maps?q=" + latitude + ',' + longitude;
            console.log(result);
        }
    }
}

That generates output like this:

2025-01-07 19:29:03: https://maps.apple.com/maps?q=30.276254,37.342880

What is the completion() function?