View Single Post
Old 06-03-2009, 05:52 PM   #3 (permalink)
paulriedel
The Visitor
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
paulriedel is on a distinguished road
Default

I ran into the same problem, also couldn't do file_get_contents(), so I'm doing page-scraping of the XML. Very dirty but quick and works until Google changes the XML response for the geocoding request. But by then I hope to have PHP 5 in place.
You will need to adjust this to work with your stuff, but this is more or less how I utilize it.

PHP Code:
    //Geocoding start
    
$id $row_Recordset1['id'];
$street $row_Recordset1['strasse_nr'];
$city $row_Recordset1['ort']; //unused as of now
$plz $row_Recordset1['plz'];
$country 'Germany';

//    $street = "Süderstrasse 77";
//    $city = "Hamburg";
//    $country = "germany";

//    $street = $_GET["street"];
//    $city = $_GET["city"];

    
$street preg_replace('/\s+/''+'$street);
    
$city preg_replace('/\s+/''+'$city);
    
$country preg_replace('/\s+/''+'$country);

    
//$street = preg_replace('?', '', $street);
    //$city = preg_replace('?', '', $city);


       // Your Google Maps API key

        
$key 'test';

    
    
$address "http://maps.google.com/maps/geo?q=$street,+$plz,+$country&output=xml&key=$key&oe=utf8&sensor=false";

       
// Retrieve the URL contents
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$address);
    
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);


    
$page=curl_exec($ch);
    
curl_close($ch);

    
$array explode(","$page);

    
$rightarray explode("\n"$page);
    
$status substr((trim($rightarray[4])),6,3);


    if (
$status == "200"){

    
$latlon explode(","$rightarray[13]);

    
$lon1 trim($latlon[0]); 
    
$lat trim($latlon[1]);
    
$lon substr($lon120); 

echo 
"<br />lat: $lat<br />Lon: $lon";
}else{
echo 
"error";

paulriedel is offline  
Reply With Quote
The Following User Says Thank You to paulriedel For This Useful Post:
Wildhoney (06-03-2009)