Es más fácil la ingeniería inversa solamente en el script final
Este código reemplaza el que tienes en la cabecera.
Ahí va:
Código Javascript
:
Ver original$(document).ready(function () {
load_map();
});
function load_map() {
var myLatlng = new google.maps.LatLng(document.getElementById("hdd_coordLatLng").value, document.getElementById("hdd_coordLng").value);
var myOptions = {
zoom: 7,
center: new google.maps.LatLng(42.846664, -2.673563),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($("#map_canvas").get(0), myOptions);
coordenadas();
}
function coordenadas() {
var ciudad = document.getElementById('ciudad').value; //El id que tengas para recoger la ciudad
if (geocoder) {
geocoder.geocode({
'address': ciudad //el mismo nombre que la variable anterior
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
document.getElementById("hdd_coordLatLng").value = results[0].geometry.location;
}
}
}
}
}
}
Te recuerdo que ya solamente va un solo campo lat lng con valor vacío
Código HTML:
Ver original<input type="hidden" name="hdd_coordLatLng" id="hdd_coordLatLng" value="" />
(Nos ahorramos la base de datos)