Yahoo BOSS Placefinder结果不准确

时间:2013-10-22 20:44:48

标签: php geolocation yahoo-api

我的公司正在使用我的前任开发的功能来地理定位地址列表。然而,自上周以来,返回的结果不准确,不是几米甚至几十公里。

决定将Yahoo BOSS API与PlaceFinder一起使用。这是功能:

function geocode_yahoo($address,$city,$state,$country) {
    $url = "http://yboss.yahooapis.com/geo/placefinder";  
    $cc_key  = "***masked for security reason ***";  
    $cc_secret = "***masked for security reason ***";     
    $consumer = new OAuthConsumer($cc_key, $cc_secret);  
    $address = array($address, $city, $state, $country);
    $address = array_filter($address);
    $args = array();  
    $args["q"] = rawurlencode(implode(' ', $address));
    $args["flags"] = "CJ";
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url,$args);  
    $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);  
    $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));  
    $ch = curl_init($url);  
    $headers = array($request->to_header());  
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");   
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  
    $rsp = curl_exec($ch);
    if ($rsp != '') {
        $data = json_decode($rsp);
        if ($data && $data->bossresponse->responsecode == '200' && intval($data->bossresponse->placefinder->count)>0) {
            return (object) array('lat'=>$data->bossresponse->placefinder->results[0]->latitude, 'lng'=>$data->bossresponse->placefinder->results[0]->longitude); 
        }
    }
return false;

}

使用的所有地址都是加拿大人,我们正在使用Oauth类。自上周以来,返回的结果没有任何意义。

例如,如果我输入地址:5275 Griffith Road,Vanderhoof,BC,Canada,我从Yahoo BOSS获得以下回复:

5275 Griffith Road, Vanderhoof, BC, CANADA

{"bossresponse":{"responsecode":"200","placefinder":{"start":"0","count":"8","request":"flags=CJ&locale=CA&q=5275%2520Griffith%2520Road%252C%2520Vanderhoof%252C%2520BC%252C%2520CANADA","results":

[{"quality":"59","latitude":"-36.71462","longitude":"139.989586","offsetlat":"-36.714619","offsetlon":"139.989578","radius":"64700"},
{"quality":"59","latitude":"47.5714","longitude":"8.115335","offsetlat":"47.5714","offsetlon":"8.11533","radius":"2100"},
{"quality":"59","latitude":"51.667509","longitude":"5.375125","offsetlat":"51.667511","offsetlon":"5.37512","radius":"3900"},
{"quality":"59","latitude":"-30.832686","longitude":"-66.089954","offsetlat":"-30.832689","offsetlon":"-66.089951","radius":"30000"},
{"quality":"59","latitude":"45.965999","longitude":"14.02893","offsetlat":"45.966","offsetlon":"14.11538","radius":"13000"},
{"quality":"59","latitude":"-32.82341","longitude":"28.05365","offsetlat":"-32.82341","offsetlon":"28.05365","radius":"11200"},
{"quality":"59","latitude":"33.824049","longitude":"35.677601","offsetlat":"33.824051","offsetlon":"35.677601","radius":"1000"},
{"quality":"39","latitude":"54.014011","longitude":"-124.012894","offsetlat":"54.014011","offsetlon":"-124.012894","radius":"9600"}]}}}

正如你所看到的,雅虎BOSS发现了一些东西(代码200),质量结果很低,59或更低。事实上他们都错了:地址在不列颠哥伦比亚省,但一些结果正在从墨西哥获得结果。最近的结果是最后一个得到39的结果。它得到了正确的城市,但不够精确。它不是唯一一个无效结果,它们是几十个具有相同结果的其他地址。

我试图输入邮政编码,将搜索限制为locale = CA,更改了地址的格式,没有什么可以改善结果。我试图将变量从$ args [“q”]更改为$ args [“location”],结果没有差异。我已经仔细检查了我们的钥匙,一切似乎都很正常。我检查了雅虎BOSS网站,询问最近是否发生了API的任何变化,没有。我已经向雅虎集团询问了与BOSS相关的问题,没有答案。我有点绝望,所以欢迎任何帮助!

1 个答案:

答案 0 :(得分:0)

好吧,似乎问题来自rawurlencode,现在Yahoo BOSS API不再需要了。他们没有回答我们,但我怀疑他们的API发生了一些变化,使得这个编码变得毫无用处。