I am new to Kintone and working on a JavaScript customization that will convert latitude written in a text field in degrees-minutes-seconds (DMS) format into decimal format.
I have the formula written to convert from DMS to decimal, but I don't know how to get the result to populate in a separate text field named "Latitude - Formula." Here is what I have so far:
(function() {
'use strict';
kintone.events.on('app.record.edit.change.latitude', function(event) {
// Split the DMS string into parts
var parts = event.value.split(/[^\d\w.]+/);
// Extract degrees, minutes, seconds, and hemisphere
var degrees = parseFloat(parts[0]);
var minutes = parseFloat(parts[1]);
var seconds = parseFloat(parts[2]);
var hemisphere = (parts[3] || 'N').toUpperCase(); // Assuming default hemisphere as 'N' if not specified
// Convert degrees, minutes, and seconds to decimal format
var decimal = degrees + (minutes / 60) + (seconds / 3600);
// Adjust the decimal latitude based on hemisphere
if (hemisphere === 'S') {
decimal *= -1; // Southern hemisphere is negative
}
//Return the decimal latitude
return decimal;
})();
The goal is to have the user type out the coordinates they need in DMS format (as shown below) and, either when they save their changes or as they are editing (if possible), convert the value they typed in and populate the field "Latitude - Formula" with the same latitude in decimal format so the field "Map Coordinates" can generate a Google Maps link to pull up a view of that location.
I know the problem is with the penultimate line "return decimal;" but I don't know how to write it such that "Latitude - Formula" is updated. Please let me know what I need to do.