PHP Classes

GeoCode minor error

Recommend this page to a friend!

      Google Geo Coding  >  All threads  >  GeoCode minor error  >  (Un) Subscribe thread alerts  
Subject:GeoCode minor error
Summary:Minor change to code
Messages:1
Author:Chris Rigg-Milner
Date:2012-01-31 15:00:35
 

  1. GeoCode minor error   Reply   Report abuse  
Picture of Chris Rigg-Milner Chris Rigg-Milner - 2012-01-31 15:00:35
Hi,

I downloaded this class to have a quick play with it and noticed the following error.

In parseGeoDate() if the result->status is != 'OK' nothing gets returned from this function.

Can I suggest this as a fix:


private function parseGeoData()
{
$data = file_get_contents($this->url);
$result = json_decode($data);

$resultFromGl = array();

if($result->status == "OK")
{
if($result->results[0]->geometry->location)
{
$addressFromGoogle = $result->results[0]->formatted_address;
$lat = $result->results[0]->geometry->location->lat;
$lng = $result->results[0]->geometry->location->lng;

$resultFromGl['status'] = $result->status;
$resultFromGl['address'] = $addressFromGoogle;
$resultFromGl['lat'] = $lat;
$resultFromGl['lng'] = $lng;

}
else
{
$resultFromGl['status'] = "Address not found";
}
}
else
{
$resultFromGl['status'] = "Address not found";
}

return $resultFromGl;
}