如何通过Google Places API获取商家“说明”?

时间:2013-05-13 16:11:04

标签: google-maps google-places-api

在Google商家信息中,在编辑我的商家时,我可以在“基本信息”下添加“说明”。顺便说一下,要进行此类修改,请转到http://www.google.com/local/add/businessCenter,然后点击商家信息下的“修改”。

当我查询Places API以了解我的业务详情时,我没有看到这个“描述”:

url = "https://maps.googleapis.com/maps/api/place/details/json?key=#{key}&sensor=#{sensor}&reference=#{reference}"

我看了Place Details Results,也没有在那里看到“说明”字段。

那么如何通过Google API查询获取地方/商家说明字段?

1 个答案:

答案 0 :(得分:-1)

该问题询问“如何获取描述”,但用户继续描述他们编辑自己业务的问题。

Google似乎没有将Place的说明存储在自己的Google商家信息数据库中,而是提供相关Freebase / Wikipedia页面的摘录

编辑业务描述的答案是“您不能直接”或“创建或编辑您的Wikipedia / Freebase页面以间接添加/修改描述”

继续阅读有关如何使用places-api“获取”业务描述的答案。此示例使用PHP。

许多维基百科文章未指明lng / lat合作,因此您无法使用Wikipedia APi进行接近/名称搜索。

然而FreeBase从维基百科中获取大部分信息,通常都有lat / lng信息。

//Gather info from Google Places API
//$_GET['gID'] is the Reference for the Place you want info for.
$url = "https://maps.googleapis.com/maps/api/place/details/json?"
        ."reference=".$_GET['gID'] 
        ."&sensor=false"
        ."&key=YOUR KEY";

$results = ProcessCurl ($url);  
$gPlace = json_decode($results);

//Gather info from FreeBase 
$url = "https://www.googleapis.com/freebase/v1/search?"
        ."indent=true"
        ."&filter=%28all"
        ."+type%3Alocation"
        ."+name%3A%22". urlencode($gPlace->result->name) ."%22"
        ."%28within+radius%3A100ft"
        ."+lon%3A". $gPlace->result->geometry->location->lng
        ."+lat%3A". $gPlace->result->geometry->location->lat ."%29%29"
        ."&output=%28description%29";           
$results = ProcessCurl ($url);  
$FreeBase = json_decode($results);

//ensure we got results from FreeBase
//All we want from FreeBase is the Description
if ($FreeBase->status == "200 OK" && $FreeBase->hits > 0)  {
$member = "/common/topic/description";
$Description = $FreeBase->result[0]->output->description->$member;
print_r ($Description[0]);

此示例使用Google Place的NAME和LAT / LNG,并在其名称为Lat / Lng的100英尺内搜索FreeBase数据库的“位置”类型。

我确信代码可以做得更好,但到目前为止效果还不错。

另外 - 有点值得注意 - 当您在谷歌搜索“地方”时,谷歌会首先搜索FreeBase,然后将该结果与类似的Google地方信息结果进行匹配。 这就是为什么当您搜索谷歌搜索某个地点时,右侧的结果可能与Google地方信息结果的名称不同,并且有描述,但是如果您使用“近”,您会注意到同一个地方现在没有描述。

例如 - 我在伦敦安大略省加拿大,我可以搜索'Fanshawe College',结果是'Fanshawe College',包括说明..但是在Map applet上,指针位于Google Place,名为'Fanshawe College - 伦敦校区'如果我改为搜索'伦敦附近的粉丝大学',那就是我正在寻找一个地方;结果我得到了'Fanshawe College - London Campus',没有任何描述和更少的信息。

相关问题