Buenas, estoy integrando un mapa de google maps en mi aplicación.
El mapa se situa en unas coordenadas dadas en un par de Inputs en formato UTM.
Al estar ya el mapa, he creado un marker y hacerlo dragable para que se pueda editar el punto al que referencio, y que me devuelva los valores.
Ya tengo el punto creado, se mueve, y me devuelve los valores lat/lng correctamente.
El problema lo tengo al realizar la conversión de latlng a UTM, puesto que veo que al mover minimamente el punto, me devuelve unos resultados erroneos.
Os dejo las partes del código correspondientes:
Evento para la edición de la posicion del marker:
Código Javascript
:
Ver originalgoogle.maps.event.addListener(marker, 'dragend', function(){
updatePosition(marker.getPosition());
});
Funcion para cambiarme la posicion en los input:
Código Javascript
:
Ver originalfunction updatePosition(latLng){
uno = parseFloat(latLng.lat());
dos = parseFloat(latLng.lng());
zona = parseFloat ("30");
var xy = new Array(2);
LatLonToUTMXY(uno,dos,zona,xy);
//var lati = "483149.550";
//var longi = "4686069.23";
jQuery('#gen_inmurb_coordenadas_x').val(xy[0]);
jQuery('#gen_inmurb_coordenadas_y').val(xy[1]);
}
Y el código que realiza la conversión de latlon a UTM:
Código Javascript
:
Ver originalfunction LatLonToUTMXY (lat, lon, zone, xy)
{
MapLatLonToXY (lat, lon, UTMCentralMeridian (zone), xy);
/* Adjust easting and northing for UTM system. */
xy[0] = xy[0] * UTMScaleFactor + 500000.0;
xy[1] = xy[1] * UTMScaleFactor;
if (xy[1] < 0.0)
xy[1] = xy[1] + 10000000.0;
return zone;
}
function MapLatLonToXY (phi, lambda, lambda0, xy)
{
var N, nu2, ep2, t, t2, l;
var l3coef, l4coef, l5coef, l6coef, l7coef, l8coef;
var tmp;
/* Precalculate ep2 */
ep2 = (Math.pow (sm_a, 2.0) - Math.pow (sm_b, 2.0)) / Math.pow (sm_b, 2.0);
/* Precalculate nu2 */
nu2 = ep2 * Math.pow (Math.cos (phi), 2.0);
/* Precalculate N */
N = Math.pow (sm_a, 2.0) / (sm_b * Math.sqrt (1 + nu2));
/* Precalculate t */
t = Math.tan (phi);
t2 = t * t;
tmp = (t2 * t2 * t2) - Math.pow (t, 6.0);
/* Precalculate l */
l = lambda - lambda0;
/* Precalculate coefficients for l**n in the equations below
so a normal human being can read the expressions for easting
and northing
-- l**1 and l**2 have coefficients of 1.0 */
l3coef = 1.0 - t2 + nu2;
l4coef = 5.0 - t2 + 9 * nu2 + 4.0 * (nu2 * nu2);
l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2
- 58.0 * t2 * nu2;
l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2
- 330.0 * t2 * nu2;
l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2);
l8coef = 1385.0 - 3111.0 * t2 + 543.0 * (t2 * t2) - (t2 * t2 * t2);
/* Calculate easting (x) */
xy[0] = N * Math.cos (phi) * l
+ (N / 6.0 * Math.pow (Math.cos (phi), 3.0) * l3coef * Math.pow (l, 3.0))
+ (N / 120.0 * Math.pow (Math.cos (phi), 5.0) * l5coef * Math.pow (l, 5.0))
+ (N / 5040.0 * Math.pow (Math.cos (phi), 7.0) * l7coef * Math.pow (l, 7.0));
/* Calculate northing (y) */
xy[1] = ArcLengthOfMeridian (phi)
+ (t / 2.0 * N * Math.pow (Math.cos (phi), 2.0) * Math.pow (l, 2.0))
+ (t / 24.0 * N * Math.pow (Math.cos (phi), 4.0) * l4coef * Math.pow (l, 4.0))
+ (t / 720.0 * N * Math.pow (Math.cos (phi), 6.0) * l6coef * Math.pow (l, 6.0))
+ (t / 40320.0 * N * Math.pow (Math.cos (phi), 8.0) * l8coef * Math.pow (l, 8.0));
return;
}
Mis disculpas, ya encontré el error, no le había pasado a radianes antes de convertirlo.
Siento las molestias, gracias.