将小数转换为纬度/经度?

时间:2012-09-25 08:39:10

标签: c#

我正在尝试GPS应用程序,我想将十进制数字转换为纬度/经度,但我没有达到确切的解决方案。我在下面尝试过

string decimalToLatLong(decimal lat,decimal refPoint)
{
 bool isNeg = lat < 0;
        int d = (int)lat;
        int m = (int)((lat - d) * 60);
        decimal s = ((((lat - d) * 60) - m) * 60);
return (d+m+s).ToString("00.000");
 if (isLat)
            direction = isNeg ? "S" : "N";
        else
            direction = isNeg ? "W" : "E";
}

1 个答案:

答案 0 :(得分:2)

怎么样:

string decimalToLatLong(decimal dec)
{
  int d = (int)dec;
  int m = (int)((dec - d) * 60);
  decimal s = ((((dec - d) * 60) - m) * 60);

  return d + "° " + m + "' " + s + "\"";
}