06-03-2009, 05:52 PM
|
#3 (permalink)
|
|
The Visitor
Join Date: Jun 2009
Posts: 1
Thanks: 0
|
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($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$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($lon1, 20);
echo "<br />lat: $lat<br />Lon: $lon";
}else{
echo "error";
}
|
|
|
|