Grados decimales a Grados°Minutos'Segundos" en JavaScript

Publicando algunos mapas en ka-map tuve que cambiar el formato de coordenadas a la notación grados minutos y segundos en JavaScript. Este­ es un pedazo de código que puede ser muy útil:

  1. function kcoords(px, py) {
  2. var x = Math.abs(x);
  3. var dx = Math.floor(x);
  4. var mx = Math.floor((x - dx)*60);
  5. var sx = Math.floor(((x - dx) - (mx/60))*3600);
  6. if (px < 0) dx = -dx;
  7. var y = Math.abs(py);
  8. var dy = Math.floor(y);
  9. var my = Math.floor((y - dy)*60);
  10. var sy = Math.floor(((y - dy) - (my/60))*3600);
  11. if (py < 0) dy = -dy;
  12. return (dx + '°' + mx + 'min ' + sx + 'seg ' + dy + '°' + my + 'min ' + sy + 'seg');
  13. }

Govctlsb (not verified) | Tue, 05/18/2010 - 11:05

Post new comment

The content of this field is kept private and will not be shown publicly.