encode static method Null safety

String encode(
  1. UTM utm,
  2. int accuracy

Encodes a UTM location as MGRS string.

@private @param {object} utm An object literal with easting, northing, zoneLetter, zoneNumber @param {number} accuracy Accuracy in digits (0-5). @return {string} MGRS string for the given UTM location.


static String encode(UTM utm, int accuracy) {
  // prepend with leading zeroes
  var seasting = '00000${utm.easting.truncate()}';
  var snorthing = '00000${utm.northing.truncate()}';
  var seastingWithAccuracy =
      seasting.substring(seasting.length - 5, seasting.length);
  seastingWithAccuracy =
      seastingWithAccuracy.substring(seastingWithAccuracy.length - accuracy);
  var snorthingWithAccuracy =
      snorthing.substring(snorthing.length - 5, snorthing.length);
  snorthingWithAccuracy = snorthingWithAccuracy
      .substring(snorthingWithAccuracy.length - accuracy);
  var value =
      '${utm.zoneNumber}${utm.zoneLetter}${get100kID(utm.easting, utm.northing, utm.zoneNumber)}$seastingWithAccuracy$snorthingWithAccuracy';
  return value;