Reputation: 21126
This is a random address I have found doesn't work and yet the address exists fine.
"Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK"
Can you guys try geocoding that and tell me if it works for you, I have 13 addresses, 12 work, this 1 doesn't?
This is the code I am running to make the geocode request:
class geocoder{
static private $url = "http://maps.google.com/maps/api/geocode/json?sensor=true&address=";
static public function getLocation($address){
$url = self::$url.urlencode($address);
$resp_json = self::curl_file_get_contents($url);
$resp = json_decode($resp_json, true);
if($resp['status']='OK'){
return $resp['results'][0]['geometry']['location'];
}else{
return false;
}
}
static private function curl_file_get_contents($URL){
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
}
$address = urlencode("Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK");
$loc = geocoder::getLocation($address);
This is proof the address exists: http://maps.google.co.uk/maps?q=%22Team+Valley+Trading+Estate,+Gateshead,+Tyne+and+Wear+NE92+1DG,+UK%22&hl=en&sll=53.103814,-2.278518&sspn=10.722701,33.815918&t=h&hnear=NE92+1DG,+United+Kingdom&z=16
This is proof that the geocoding class should be returning data:
Upvotes: 1
Views: 733
Reputation: 100175
you are urlencod'ing the address twice so change:
$address = urlencode("Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK");
to
$address = "Team Valley Trading Estate, Gateshead, Tyne and Wear NE92 1DG, UK";
as you have urlencod'ed the address in your getLocation
function
Upvotes: 2