Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/01/2011, 06:12
bleenk
 
Fecha de Ingreso: julio-2008
Mensajes: 15
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Xpath y acceso a XML's

Muchas gracias abimaelrc :) Sin ti me hubiera sido imposible.

Comparto aquí el código de la función por si a alguien le sirve aunque pensaba publicar la clase entera cuando la tenga terminada, si alguien la necesita que me avise (es para codeigniter, pero no cuesta nada adaptarla).

Código PHP:
function locate() {
        
$base_url "http://maps.google.es/maps/geo?output=xml&key=" apiKey "&oe=utf8";
        
$query $this->getAddress() . " " $this->getCity() . " " $this->getPostalCode();
        
$request_url $base_url "&q=" urlencode($query); //construct http request
        
$strResponse file_get_contents($request_url);
        
$strResponse str_replace(' xmlns="http://earth.google.com/kml/2.0"'''$strResponse);
        
$xml = new SimpleXMLElement($strResponse);

        
$result $xml->xpath('//kml/Response/Placemark/Point/coordinates'); //also  $xml->xpath('//coordinates');
        
$coordinates explode(","$result[0]);
        
$arrayCoords = array("x" => $coordinates[0], "y" => $coordinates[1]);
        return(
$arrayCoords);
    }