Map point to DMS

2565
2
01-26-2013 07:16 AM
Udaya_BhaskerCheerala
New Contributor
Dear All,

I would like to conver map coordinates (-103.5234,48.56781) to DMS(Degrees Minutes Sec). My map is in WKI:4269.

Can anybody help me how to do it in JSAPI.

Thanks,
Uday
0 Kudos
2 Replies
JeffJacobson
Occasional Contributor III
Dear All,

I would like to conver map coordinates (-103.5234,48.56781) to DMS(Degrees Minutes Sec). My map is in WKI:4269.

Can anybody help me how to do it in JSAPI.

Thanks,
Uday


I've written code to perform the conversion the other way (DMS to DD).

I did a search and found a lot of samples for doing the conversion from DD to DMS. This one looks promising.
0 Kudos
khairulamri
Occasional Contributor

Hi,

Here is my code to show DMS coordinates on Map Screen using ArcGIS API Javascript

// Coordinates on Screen
  map.on("load", function() {
   //after map loads, connect to listen to mouse move & drag events
   map.on("mouse-move", showCoordinates);
   map.on("mouse-drag", showCoordinates);
  });

  function deg_to_dms (deg) {
    var d = Math.floor (deg);
    var minfloat = (deg-d)*60;
    var m = Math.floor(minfloat);
    var secfloat = (minfloat-m)*60;
    var s = Math.round(secfloat);
    
    if (s==60) {
  m++;
  s=0;
    }
    if (m==60) {
  d++;
  m=0;
    }
    return ("" + d + '°' + m + '\'' + s + '" ');
  }

  function showCoordinates(evt) {

   //the map is in web mercator but display coordinates in geographic (lat, long)
   var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
  //convert DD to DMS
     var lat = deg_to_dms(mp.y);
   var lon = deg_to_dms(mp.x);
   //display mouse coordinates
   dom.byId("coordinate").innerHTML = lat + 'N' + ", " + lon + 'E';
  }

Regards,

Amri

0 Kudos