Ver Mensaje Individual
  #7 (permalink)  
Antiguo 20/06/2012, 09:36
txemaarbulo
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Geocoding API en PHP

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
  1. $(document).ready(function () {
  2.   load_map();
  3. });
  4.  
  5. function load_map() {
  6.   var myLatlng = new google.maps.LatLng(document.getElementById("hdd_coordLatLng").value, document.getElementById("hdd_coordLng").value);
  7.   var myOptions = {
  8.     zoom: 7,
  9.     center: new google.maps.LatLng(42.846664, -2.673563),
  10.     mapTypeId: google.maps.MapTypeId.ROADMAP
  11.   };
  12.   var map = new google.maps.Map($("#map_canvas").get(0), myOptions);
  13.   coordenadas();
  14. }
  15.  
  16. function coordenadas() {
  17.   var ciudad = document.getElementById('ciudad').value;  //El id que tengas para recoger la ciudad
  18.   if (geocoder) {
  19.     geocoder.geocode({
  20.       'address': ciudad //el mismo nombre que la variable anterior
  21.       function (results, status) {
  22.       if (status == google.maps.GeocoderStatus.OK) {
  23.         if (results[0]) {
  24.           document.getElementById("hdd_coordLatLng").value = results[0].geometry.location;
  25.           }
  26.        }      
  27.       }
  28.     }
  29.   }
  30. }

Te recuerdo que ya solamente va un solo campo lat lng con valor vacío
Código HTML:
Ver original
  1. <input type="hidden" name="hdd_coordLatLng" id="hdd_coordLatLng" value="" />

(Nos ahorramos la base de datos)

Última edición por txemaarbulo; 20/06/2012 a las 09:45