0

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

决定将 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"}]}}}

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

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

4

1 回答 1

0

好的,看来问题出在 rawurlencode 上,现在使用 Yahoo BOSS API 是不必要的。他们从来没有回答过我们,但我怀疑他们的 API 中的一些变化会使这种编码变得无用。

于 2013-10-25T19:50:54.840 回答