Ver Mensaje Individual
  #5  
Antiguo 18-09-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Iván.
Cita:
Empezado por radenf Ver Mensaje
...
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
  // Signos
  laPCar:= UpCase(LatStr[Length(LatStr)]);
  loPCar:= UpCase(LonStr[Length(LonStr)]);
  LASIGN:= VSIGN[laPCar = 'S'];
  LOSIGN:= VSIGN[loPCar in ['O','W']];
  ts:= TStringList.Create;
  try
    // Latitud
    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);
    // Longitud
    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);
  // Calculos latitud
  laDegA:= Abs(Round(laDeg * 1000000));
  laMinA:= Abs(Round(laMin * 1000000));
  laSecA:= Abs(Round(laSec * 1000000));
  // Calculos longitud
  loDegA:= Abs(Round(loDeg * 1000000));
  loMinA:= Abs(Round(loMin * 1000000));
  loSecA:= Abs(Round(loSec * 1000000));
  // Verificar latitud
  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');
  // Verificar longitud
  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');
  // Resultado
  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
  // Como siempre el pueblo tira...
  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;
  // A probar a google maps...
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 18-09-2014 a las 20:26:40. Razón: acomodar identación
Responder Con Cita