Hola Iván.
Cita:
Empezado por radenf
...
En mi programa he implementado el uso de un javascript que llama a GoogleMaps sobre un TWebBrowser, que sólo acepta el formato de grados decimal (DDD)...
|
Ya había olvidado por que detestaba javascript... hasta ahora
Lo verifiqué con varias localizaciones y anduvo bién, pero fijate si en en las futuras pruebas continúa hacíendolo...
Código Delphi
[-]
uses Clipbrd;
procedure CoordSexaToDec(const LatStr,LonStr: string; var Latitude,Longitude: Double);
{$J+}
const
LASIGN: ShortInt = 1;
LOSIGN: ShortInt = 1;
VSIGN : array[Boolean] of ShortInt = (1,-1);
{$J-}
var
laPCar, loPCar: Char;
laDeg, loDeg: Double;
laMin, loMin: Double;
laSec, loSec: Double;
laDegA, loDegA: Double;
laMinA, loMinA: Double;
laSecA, loSecA: Double;
ts : TStrings;
begin
laPCar:= UpCase(LatStr[Length(LatStr)]);
loPCar:= UpCase(LonStr[Length(LonStr)]);
LASIGN:= VSIGN[laPCar = 'S'];
LOSIGN:= VSIGN[loPCar in ['O','W']];
ts:= TStringList.Create;
try
ts.CommaText:= LatStr;
ts[2] := Copy(ts[2], 1, Pos('/', ts[2]) - 1);
laSec := StrToFloat(ts[2])/100;
laMin := StrToFloat(ts[1]);
laDeg := StrToFloat(ts[0]);
laSec := Abs(Round(laSec * 1000000) / 1000000);
laMin := Abs(Round(laMin * 1000000) / 1000000);
ts.Clear;
ts.CommaText:= LonStr;
if loPCar = 'O' then loPCar:= 'W';
ts[2] := Copy(ts[2], 1, Pos('/', ts[2]) - 1);
loSec := StrToFloat(ts[2])/100;
loMin := StrToFloat(ts[1]);
loDeg := StrToFloat(ts[0]);
finally
ts.Free;
end;
loSec := Abs(Round(loSec * 1000000) / 1000000);
loMin := Abs(Round(loMin * 1000000) / 1000000);
laDegA:= Abs(Round(laDeg * 1000000));
laMinA:= Abs(Round(laMin * 1000000));
laSecA:= Abs(Round(laSec * 1000000));
loDegA:= Abs(Round(loDeg * 1000000));
loMinA:= Abs(Round(loMin * 1000000));
loSecA:= Abs(Round(loSec * 1000000));
if not (laPCar in ['N','S']) then
raise Exception.Create('Error en la latitud');
if not (loPCar in ['E','W']) then
raise Exception.Create('Error en la longitud');
if laDegA > 90 * 1000000 then
raise Exception.Create('Error: Grados en latitud: -90 a 90');
if laMinA > 60 * 1000000 then
raise Exception.Create('Error: Minutos en latitud: 0 a 59');
if laSecA > 59.99999999 * 1000000 then
raise Exception.Create('Error: Segundos en latitud: 0 a 60');
if loDegA > 180 * 1000000 then
raise Exception.Create('Error: Grados en longitud: -180 a 180');
if loMinA > 60 * 1000000 then
raise Exception.Create('Error: Minutos en longitud: 0 a 59');
if loSecA > 59.99999999 * 1000000 then
raise Exception.Create('Error: Segundos en longitud: 0 a 60');
Latitude := Round(laDegA + laMinA / 60 + laSecA / 3600)* LASIGN / 1000000;
Longitude:= Round(loDegA + loMinA / 60 + loSecA / 3600) * LOSIGN / 1000000;
end;
procedure TForm1.btnConvierteClick(Sender: TObject);
var
Exif1, Exif2: string;
Latitud, Longitud: Double;
begin
Exif1:= '38,22,37/100S';
Exif2:= '60,16,31/100W';
CoordSexaToDec(Exif1,Exif2,Latitud,Longitud);
Exif1:= StringReplace(FloatToStr(Latitud),',','.',[rfReplaceAll]);
Exif2:= StringReplace(FloatToStr(Longitud),',','.',[rfReplaceAll]);
Clipboard.AsText:= Exif1 + ', ' + Exif2;
end;
Saludos