<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602546#M86815</link>
    <description>&lt;P&gt;We are using the toLatitudeLongitude method of the coordinateFormatter to get a string representation of a given point object.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-coordinateFormatter.html#toLatitudeLongitude" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-coordinateFormatter.html#toLatitudeLongitude&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, for the cases where the decimalPlaces are set to 0 it adds a leading zero infront of the minute-value leading to a three-digit-value. Thats obviously wrong since minutes only range til 60, so any leading hundet-zero is simply wrong here.&lt;/P&gt;&lt;P&gt;We were pointed on that by some technical experts which are working with coordinates every day.&lt;/P&gt;&lt;P&gt;I did some research and only can find samples and references without a leading hundred-zero.&lt;/P&gt;&lt;P&gt;Can anyone explain me, why esri is doing that? Is there may a function to correct the string?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2025 21:33:36 GMT</pubDate>
    <dc:creator>SebastianKrings</dc:creator>
    <dc:date>2025-04-03T21:33:36Z</dc:date>
    <item>
      <title>esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602546#M86815</link>
      <description>&lt;P&gt;We are using the toLatitudeLongitude method of the coordinateFormatter to get a string representation of a given point object.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-coordinateFormatter.html#toLatitudeLongitude" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-coordinateFormatter.html#toLatitudeLongitude&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, for the cases where the decimalPlaces are set to 0 it adds a leading zero infront of the minute-value leading to a three-digit-value. Thats obviously wrong since minutes only range til 60, so any leading hundet-zero is simply wrong here.&lt;/P&gt;&lt;P&gt;We were pointed on that by some technical experts which are working with coordinates every day.&lt;/P&gt;&lt;P&gt;I did some research and only can find samples and references without a leading hundred-zero.&lt;/P&gt;&lt;P&gt;Can anyone explain me, why esri is doing that? Is there may a function to correct the string?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 21:33:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602546#M86815</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2025-04-03T21:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602822#M86826</link>
      <description>&lt;P&gt;Hi Sebastian, I raised this issue very recently! it was confirmed as a bug:&amp;nbsp;&lt;STRONG&gt;&lt;SPAN class=""&gt;BUG&lt;/SPAN&gt;-000172707&lt;/STRONG&gt;&lt;SPAN&gt; - The ArcGIS Maps SDK for JavaScript coordinateFormatter function converts points incorrectly when the toLatitudeLongitude method has the decimalPlaces parameter set to zero&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 15:34:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602822#M86826</guid>
      <dc:creator>JonathanDawe_BAS</dc:creator>
      <dc:date>2025-04-04T15:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602983#M86829</link>
      <description>&lt;P&gt;good to know&lt;/P&gt;&lt;P&gt;the bug page doesnt bring much info about details&lt;BR /&gt;&lt;A href="https://support.esri.com/de-de/bug/the-arcgis-maps-sdk-for-javascript-coordinateformatter-bug-000172707" target="_blank" rel="noopener"&gt;https://support.esri.com/de-de/bug/the-arcgis-maps-sdk-for-javascript-coordinateformatter-bug-000172707&lt;/A&gt;&lt;/P&gt;&lt;P&gt;one should also note, that the wrong output is also part of the documentation which means that the current implementation isnt just buggy but wrong by design.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/833978"&gt;@JonathanDawe_BAS&lt;/a&gt;&amp;nbsp;: can we ensure, that the wrong hundred-zero is exactly what will be fixed by this bug? if so, we can await the fix. If this could not be ensured we would first go with a workaround.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 20:53:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1602983#M86829</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2025-04-04T20:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1603179#M86831</link>
      <description>&lt;P&gt;I've actually steered away from using the coordinate.formatter for formatting from a point to a string. I personally only use it for converting the other way from a string to a point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rationale was that we wanted a bit more control over the formatting - For example presenting DDM as &lt;SPAN&gt;54°16.544' S, 36°26.348' W instead of 54 16.544S 36 26.348W.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export type DisplayFormat = 'DD' | 'DMS' | 'DDM';

export const BLANK_COORDINATES = {
  DD: '--.-° N, --.-° E',
  DMS: '--°--\'--\" N, --°--\'--\" E',
  DDM: "--°--.--' N, --°--.--' E",
} as const;

// Utility functions for coordinate conversions
export function decimalToDMS(degree: number, isLat: boolean) {
  const absolute = Math.abs(degree);
  const degrees = Math.floor(absolute);
  const minutesNotTruncated = (absolute - degrees) * 60;
  const minutes = Math.floor(minutesNotTruncated);
  const seconds = ((minutesNotTruncated - minutes) * 60).toFixed(2);
  const direction = isLat ? (degree &amp;gt;= 0 ? 'N' : 'S') : degree &amp;gt;= 0 ? 'E' : 'W';
  return `${degrees}°${minutes}'${seconds}" ${direction}`;
}

export function decimalToDDM(degree: number, isLat: boolean) {
  const absolute = Math.abs(degree);
  const degrees = Math.floor(absolute);
  const minutes = ((absolute - degrees) * 60).toFixed(3);
  const direction = isLat ? (degree &amp;gt;= 0 ? 'N' : 'S') : degree &amp;gt;= 0 ? 'E' : 'W';
  return `${degrees}°${minutes}' ${direction}`;
}

export function formatLatitude(latitude: number) {
  const direction = latitude &amp;gt;= 0 ? 'N' : 'S';
  const absoluteValue = Math.abs(latitude).toFixed(2);
  return `${absoluteValue}° ${direction}`;
}

export function formatLongitude(longitude: number) {
  const direction = longitude &amp;gt;= 0 ? 'E' : 'W';
  const absoluteValue = Math.abs(longitude).toFixed(2);
  return `${absoluteValue}° ${direction}`;
}

export function formatCoordinate(
  lat: number | nullish,
  lon: number | nullish,
  format: DisplayFormat,
  displayPlaceholder: boolean = false,
) {
  if (!isDefined(lat) || !isDefined(lon))
    return displayPlaceholder ? BLANK_COORDINATES[format] : null;

  switch (format) {
    case 'DD':
      return `${formatLatitude(lat)}, ${formatLongitude(lon)}`;
    case 'DMS':
      return `${decimalToDMS(lat, true)}, ${decimalToDMS(lon, false)}`;
    case 'DDM':
      return `${decimalToDDM(lat, true)}, ${decimalToDDM(lon, false)}`;
    default:
      return null;
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 07:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1603179#M86831</guid>
      <dc:creator>JonathanDawe_BAS</dc:creator>
      <dc:date>2025-04-07T07:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1606617#M86959</link>
      <description>&lt;P&gt;this is awesome. Grate you share your code here.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 18:33:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1606617#M86959</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2025-04-16T18:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: esri geometry coordinateFormatter toLatitudeLongitude using wrong minute format</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1606705#M86960</link>
      <description>&lt;P&gt;This is my workaround to cut out the zeros until the fix is released:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    /**
     * This is a Bugfix of Esri coordinateFormatter.toLatitudeLongitude
     * The Bug is already tracked and in product plan.
     * Which means it may be fixed in the next two releases of ArcGIS.
     * Bug link:
     * https://support.esri.com/en-us/bug/the-arcgis-maps-sdk-for-javascript-coordinateformatter-bug-000172707
     * 
     * Nevertheless this method fixes the wrong output as workaround.
     * The problem is, that the minutes are printed as three-digit with leading zeros
     *  although minutes only reach to max. 60.
     * Within this methode the leading hundredth-zero is cut out while a possible tenth-zero is kept.
     * The issue is known for formats 'ddm' and 'dms'.
     * If the given format is anything else, the original coordinates are returned.
     * 
     * For both ddm and dms the leading hunderdth-zeros can be found by the hemisphere characters.
     * The fix applies for precision = 0.
     * DDM sample: 55 057N 003 010W
     * DMS sample: 55 56 039N 003 09 043W
     * 
     * For latitude we determine the index of the N- or S-character.
     * For longitude we determine the index of the O- or W-character.
     * The leading hundredth-zero is located at index - 3 for both lat- and lon-index.
     *  coordinates to be fixed
     *  format of the coordinates
     * @returns a fixed version of the coordinates if format is of ddm or dms, otherwise the original coordinates are returned.
     */
    private fixBuggyMinuteCoordinateFormat(coordinates: string, format: string): string {
        // only process for formats ddm and dms
        if (format === 'ddm' || format === 'dms') {
            const regex_lat = /[NS]/;
            const regex_lon = /[EW]/;
            const match_lat = regex_lat.exec(coordinates);
            const match_lon = regex_lon.exec(coordinates);
            // only process if string contains N or S
            if (match_lat &amp;amp;&amp;amp; match_lon) {
                const lat_i = match_lat.index - 3;
                const lon_i = match_lon.index - 3;
                // only process if there is a 0 at both indices
                if (coordinates.charAt(lat_i) === '0' &amp;amp;&amp;amp; coordinates.charAt(lon_i) === '0') {
                    //remove the longitudes zero first
                    coordinates = coordinates.slice(0, lon_i) + coordinates.slice(lon_i + 1);
                    //remove the latitudes zero second
                    coordinates = coordinates.slice(0, lat_i) + coordinates.slice(lat_i + 1);
                }
            }
        }
        return coordinates;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 21:32:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-geometry-coordinateformatter/m-p/1606705#M86960</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2025-04-16T21:32:22Z</dc:date>
    </item>
  </channel>
</rss>

