Hola de nuevo amigo,
He conseguido cojer las coordenadas apartir del codigo que me has enviado, la unica cosa que me falta es que cuando movemos la marca las coordenadas no se actualizan,
A ver si puede echarme una manilla.
este es el codigo completo:
Código HTML:
Ver original<script src="http://maps.google.com/maps?file=api&v=2.x&key=AIzaSyB6aZ5WHW3WiTHExADSYls_fal7ez3o504" type="text/javascript"></script> <script src="http://maps.google.com/maps?file=api&v=2.x&key=AIzaSyB6aZ5WHW3WiTHExADSYls_fal7ez3o504" type="text/javascript"></script> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw" type="text/javascript"></script> <script type="text/javascript">
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 1);
map.setUIToDefault();
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 15);
var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);
GEvent.addListener(marker, "dragend", function() {
if(document.getElementById('address').value != "") {
var address = document.getElementById('address').value;
geocoder.getLatLng(address, function(point) {
if (!point) {
alert(address + ' no encontrado');
} else {
document.getElementById('latitud').value = point.y;
document.getElementById('longitud').value = point.x;
}
});}
});
GEvent.addListener(marker, "click", function() {
if(document.getElementById('address').value != "") {
var address = document.getElementById('address').value;
geocoder.getLatLng(address, function(point) {
if (!point) {
alert(address + ' no encontrado');
} else {
document.getElementById('latitud').value = point.y;
document.getElementById('longitud').value = point.x;
}
});}
});
GEvent.trigger(marker, "click");
}
}
);
}
}
<body onload="initialize()" onunload="GUnload()"> <form action="#" onsubmit="showAddress(this.address.value); return false"> Enter an address, and then drag the marker to tweak the location.
The latitude/longitude will appear in the infowindow after each geocode/drag.
<input type="text" style="width:350px" name="address" id="address" value="1600 Amphitheatre Pky, Mountain View, CA" /> <div id="map_canvas" style="width: 600px; height: 400px"></div> <input name="latitud" type="text" id="latitud" size="45" /> <input name="longitud" type="text" id="longitud" size="45" />
Con esto ya podria enviar las coordenadas mediante un form y guardarlas en la base de datos.
Bueno un saludo amigo