首页  编辑  

浮点数转换为经纬度坐标

Tags: /超级猛料/Format.格式,单位/Unit.单位/   Date Created:

将一个浮点数转换为 多少度,多少分,多少秒的格式

const

 CsAngleDegree = '°';

 CsAngleMinute = '′';

 CsAngleSecond = '″';

 CSCoordShortTitle: array[boolean, boolean] of string = (('W', 'E'), ('S', 'N'));

function AngleXToStr(Value: Double; LeadZero: Boolean): string;

var

 Plus: Boolean;

 sFormat: string;

begin

 Plus := Value >= 0;

 Value := Abs(Value);

 if LeadZero then sFormat := '%s%0.3d%s' else sFormat := '%s%d%s';

 Result := Format(sFormat, [CSCoordShortTitle[False, Plus], Trunc(Value), CsAngleDegree]);

 Value := Abs(Value - Int(Value)) * 60.0;

 if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';

 Result := Format(sFormat, [Result, Trunc(Value), CsAngleMinute]);

 Value := (Value - Int(Value)) * 60.0;

 if LeadZero then sFormat := '%s%5.2f%s' else sFormat := '%s%0.2f%s';

 Result := Format(sFormat, [Result, Value, CsAngleSecond]);

end;

function AngleYToStr(Value: Double; LeadZero: Boolean): string;

var

 Plus: Boolean;

 sFormat: string;

begin

 Plus := Value >= 0;

 Value := Abs(Value);

 if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';

 Result := Format(sFormat, [CSCoordShortTitle[True, Plus], Trunc(Value), CsAngleDegree]);

 Value := Abs(Value - Int(Value)) * 60.0;

 if LeadZero then sFormat := '%s%0.2d%s' else sFormat := '%s%d%s';

 Result := Format(sFormat, [Result, Trunc(Value), CsAngleMinute]);

 Value := (Value - Int(Value)) * 60.0;

 if LeadZero then sFormat := '%s%5.2f%s' else sFormat := '%s%0.2f%s';

 Result := Format(sFormat, [Result, Value, CsAngleSecond]);

end;

DMS经纬度转化成浮点数:

R = D + M/60 + S/3600