Show Mouse Coordinates in lat long

2586
3
03-22-2012 10:03 AM
DeeptiVB
New Contributor II
I want to implement this example, but would like to show the mouse coords  in lat long instead of decimal degrees. Any pointers?
Thanks,
-Deepti
0 Kudos
3 Replies
HugoCardenas
New Contributor
Assuming that your input coordinates are decimal degrees, run the following method to return a string of Degrees Minutes and Seconds:
    protected string ConvertToDMS(double decimalDegrees)
    {
      string dms = string.Empty;

      // Get degrees
      double dd = Math.Abs(decimalDegrees);
      double degrees = Math.Floor(dd);

      // Get minutes
      dd = dd - Math.Floor(dd);
      dd *= 60;
      double minutes = Math.Floor(dd);

      // Seconds.
      // Math to eliminate eensy and teensy fractions of seconds.
      double seconds = 60 * (dd - Math.Floor(dd));
      seconds *= 1000;
      seconds = Math.Round(seconds);
      seconds /= 1000;

      if (seconds >= 60)
      {
        seconds -= 60;
        minutes++;
      }

      if (minutes >= 60)
      {
        minutes -= 60;
        degrees++;
      }

      string degreesText = Math.Floor(degrees).ToString();
      string minutesText = Math.Floor(minutes).ToString();
      string formattedSeconds = seconds.ToString("N2");
      char chr = (char)176;
      string degreeSymbol = chr.ToString();

      dms = degreesText + degreeSymbol + "  " + minutesText + "'" + "  " + formattedSeconds + "\"";
      return dms;
    }
0 Kudos
JenniferNery
Esri Regular Contributor
You can also use Webmercator.ToGeographic()

                       var webMercator = new WebMercator();
                       var result = webMercator.ToGeographic(mapPoint) as MapPoint;  
0 Kudos
DeeptiVB
New Contributor II
Thank you both for your replies. I was able to successfully implement Jennifer's solution. Appreciate it!

I did get the math behind Hugo's function. But my app's coordinates are not in decimal degrees(my mistake, in the initial post), the coordinates in my app are exactly like in the Silverlight API sample I linked to. Seems to be UTM. For example for 60.7344(now that's decimal degrees) latitude, my app's co-ordinates show up the lat value as 8565096.38759.
0 Kudos