// Json encode the data
function json_code ($json)
{
$json = substr($json, strpos($json,'{')+1, strlen($json));
$json = substr($json, 0, strrpos($json,'}'));
$json=preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s','$1"$3"$4:',trim($json));
return json_decode('{'.$json.'}', true);
}
// function to get the geocode of the address
function geoCodeYp($point)
{
$yahoo_appid = 'Your yahoo app id'; // Replace your Yahoo AppID here
$pointenc = urlencode($point);
// URL Formation that will fetch you the results on query
$url="http://where.yahooapis.com/geocode? location=".$pointenc."&gflags=R&appid=".$yahoo_appid."&flags=J";
// get the contents of the URL formed
$jsondata = file_get_contents($url);
$json_data= '{
a: 1,
b: 245,
c with whitespaces: "test me",
d: "function () { echo \"test\" }",
e: 5.66
}';
$coord=explode(" ",$point); // this will json encode the data .
$convertedtoarray=$this->json_code($jsondata); // line1 of addrress comprising of house,street no etc // line 2 of address comprising of city state country
$line1 =$convertedtoarray['ResultSet']['Results']['0']['line1'] ;
$line2 =$convertedtoarray['ResultSet']['Results']['0']['line1'] ;
$county =$convertedtoarray['ResultSet']['Results']['0']['county'] ;
$street =$convertedtoarray['ResultSet']['Results']['0']['street'] ;
if(($line1=="")||($line2=="")||($county=="")||($street==""))
{
$yahooresults['status']="noresult";
}
else
{
$countrycode=$convertedtoarray['ResultSet']['Results']['0']['countrycode'] ;
$statecode =$convertedtoarray['ResultSet']['Results']['0']['statecode'] ;
//$county =$convertedtoarray['ResultSet']['Results']['0']['county'] ;
$city =$convertedtoarray['ResultSet']['Results']['0']['city'] ;
$house =$convertedtoarray['ResultSet']['Results']['0']['house'] ;
$latitude =$convertedtoarray['ResultSet']['Results']['0']['latitude'] ;
$longitude =$convertedtoarray['ResultSet']['Results']['0']['longitude'] ;
$yahooresults = array('countrycode'=>$countrycode,'statecode'=>$statecode,'county'=>$county,'city'=>$city,'street'=>$street,'house'=>$house, 'latitude'=>$latitude,'longitude'=>$longitude); }
return $yahooresults ;
}
|