Google Places API 结果与 Google 搜索不匹配
Posted
技术标签:
【中文标题】Google Places API 结果与 Google 搜索不匹配【英文标题】:Google Places API results do not match Google search 【发布时间】:2014-10-24 03:40:57 【问题描述】:在我的数据中,我发现了许多类似以下的示例。如果您在 Google 上搜索“Cheyney University PA”,您会得到以下信息:
地址:1837 University Cir, Cheyney, PA 19319 电话:(610) 399-2000
但是,当使用以下方法进行搜索时:
my $pid_url = Mojo::URL->new('https://maps.googleapis.com/maps/api/place/textsearch/json');
$pid_url->query(query => $query, key => 'removed');
my $place_id = $ua->get($pid_url)->res->json->results->[0]->place_id;
# Query = https://maps.googleapis.com/maps/api/place/textsearch/json?query=Cheyney+University+PA&key=removed
# Place ID returned = ChIJ5wiPkSvuxokR2rwaVUTMwks
$deets_url = Mojo::URL->new('https://maps.googleapis.com/maps/api/place/details/json');
$deets_url->query(placeid => $place_id, key => 'removed');
say $ua->get($deets_url)->res->body;
我从 Google 收到以下回复:
"result" :
"address_components" : [
"long_name" : "Cheyney",
"short_name" : "Cheyney",
"types" : [ "locality", "political" ]
,
"long_name" : "Thornbury",
"short_name" : "Thornbury",
"types" : [ "administrative_area_level_3", "political" ]
,
"long_name" : "Delaware County",
"short_name" : "Delaware County",
"types" : [ "administrative_area_level_2", "political" ]
,
"long_name" : "Pennsylvania",
"short_name" : "PA",
"types" : [ "administrative_area_level_1", "political" ]
,
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
],
"formatted_address" : "Cheyney, PA, USA",
"name" : "Cheyney",
"place_id" : "ChIJ5wiPkSvuxokR2rwaVUTMwks",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/maps/place?q=Cheyney,+PA,+USA&ftid=0x89c6ee2b918f08e7:0x4bc2cc44551abcda",
"vicinity" : "Cheyney"
,
"status" : "OK"
(为了清楚起见,我删除了一些输出。)请注意,结果中缺少街道地址组件(1837 University Cir)以及电话号码。我发现了很多这样的例子,我试图弄清楚为什么我的查询返回的结果与我在谷歌搜索信息时得到的结果不同。
这是另一个例子:
谷歌搜索结果:
地址:1320 S Dixie Hwy, Coral Gables, FL 33124 电话:(305) 284-2211
Places API 结果:
"html_attributions" : [],
"results" : [
"formatted_address" : "University of Miami, Coral Gables, FL 33146, USA",
"geometry" :
"location" :
"lat" : 25.7216374,
"lng" : -80.2792843
,
"viewport" :
"northeast" :
"lat" : 25.7316894,
"lng" : -80.26327689999999
,
"southwest" :
"lat" : 25.7115846,
"lng" : -80.29529169999999
,
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7eb529034293a6eb760e990e034a4314d83edcf7",
"name" : "University of Miami",
"place_id" : "ChIJn9K4n_C32YgRqR37uAXB5IM",
"reference" : "CqQBnAAAACffq3Xp3JUFowUDlEsge90htrhAoUES9tGmsB919iNQCxgldtq4khP4f_gCAju90qGY1IEUH52hZl_GP_H6xJC5z22EceCfprWEHFhhXKsW23Y9EeV24svXC-PRYnOyQaXZmbQFCeUlsmKWB6570e-8W_w31muZKwFd4hVPdeeqO45zH2zp7CAuSrHjBr0bSiOQufEB59ibxG4QcuwenSASEHvq1xMcCCtMUsFcyLYsrOIaFN0vg6S680hJay1jDSrZ686Mt9Gn",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
],
"status" : "OK"
"html_attributions" : [],
"result" :
"address_components" : [
"long_name" : "University of Miami",
"short_name" : "University of Miami",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
,
"long_name" : "Coral Gables",
"short_name" : "Coral Gables",
"types" : [ "locality", "political" ]
,
"long_name" : "Miami-Dade County",
"short_name" : "Miami-Dade County",
"types" : [ "administrative_area_level_2", "political" ]
,
"long_name" : "Florida",
"short_name" : "FL",
"types" : [ "administrative_area_level_1", "political" ]
,
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
,
"long_name" : "33146",
"short_name" : "33146",
"types" : [ "postal_code" ]
],
"adr_address" : "University of Miami, \u003cspan class=\"locality\"\u003eCoral Gables\u003c/span\u003e, \u003cspan class=\"region\"\u003eFL\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e33146\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "University of Miami, Coral Gables, FL 33146, USA",
"geometry" :
"location" :
"lat" : 25.7216374,
"lng" : -80.2792843
,
"viewport" :
"northeast" :
"lat" : 25.7316894,
"lng" : -80.26327689999999
,
"southwest" :
"lat" : 25.7115846,
"lng" : -80.29529169999999
,
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "7eb529034293a6eb760e990e034a4314d83edcf7",
"name" : "University of Miami",
"place_id" : "ChIJn9K4n_C32YgRqR37uAXB5IM",
"reference" : "CqQBlAAAAFeKC7LbGqAr7-LnBXMqbMIhuyuUh22XBMRO11hADojDclomC-InGocKSStmZ8S-S1UVWC1qHAsZi3XSp7PiDOFBgZVMqhm5kr87CfEAJmPdwsmZ6VEg5FxXh5LZmSSZdFgH0UR0OVGLL5M17SmWZp4W3Die8UNa5yCMyV5CP0T0VWmvqCb54qJR6mlyIx1itiLzRp1XhTs8_UmEt9pjIkYSEGrAqS6TWo2G1WBOrDO0YSAaFO4FfqvmFabJLia36vKL0XTz23Mu",
"scope" : "GOOGLE",
"types" : [ "sublocality_level_1", "sublocality", "political" ],
"url" : "https://maps.google.com/maps/place?q=University+of+Miami,+Coral+Gables,+FL+33146,+USA&ftid=0x88d9b7f09fb8d29f:0x83e4c105b8fb1da9",
"vicinity" : "University of Miami"
,
"status" : "OK"
【问题讨论】:
【参考方案1】:您似乎想使用 Google 地图进行某种地址验证和解析。简短的故事是,不幸的是,谷歌地图不能被回复以一致地返回解析的地址组件。谷歌地图做得很好的是地理编码 - 即将输入转换为纬度/经度以显示在地图上。您或许可以尝试反向地理编码(即给 Google 经纬度)以查看返回的结果,但我很确定您会得到类似的结果。
我自己过去也曾想使用类似的谷歌地图,但徒劳无功。在对各种国际现实世界数据集进行大量测试后,我得出结论,Google 不能用于验证,只是(a)获取纬度/经度(b)一般是/否,地址看起来不错。我还尝试了其他一些地理编码提供商,后来当我的网站超出了他们以前免费提供的内容时,谷歌证明太贵了,于是我选择了 GeocodeFarm。不过,我的一般结论是相同的——我必须坚持使用相当传统的地址数据输入表格,而无需“完全验证”验证,否则用户会被告知地址错误而实际上是有效的。尽管 GeocodeFarm 确实“漂亮地打印”了本地化地址(即几乎适合作为邮寄标签放在信封上),但它没有被解析成组件以存储到典型的关系数据库模式中。
做更多的研究来验证我自己的经验,我发现this 和this 很有用。这些链接还指向一个名为“SmartyStreets”的服务——但是我不能保证它,并且对它的经验为零。
希望有帮助!
【讨论】:
不,这并不能真正回答我的问题。我的问题是,为什么对他们的 API 的查询与在浏览器中对谷歌地图的完全相同的查询产生不同的结果? 啊,这就是你要问的。 ***.com/questions/10567487/… 伙计,一个重复的问题!如果我删除问题,我还能奖励你吗?您链接到的内容确实回答了问题。 很容易做到。哈我不知道赏金,但我希望如此,我是 SO 贡献的新手,可以与代表一起做,如果你已经付钱了,这似乎是一种浪费!根据我阅读的内容,这是不可退还的。以上是关于Google Places API 结果与 Google 搜索不匹配的主要内容,如果未能解决你的问题,请参考以下文章
获取与 Google Places/Geocoding API 的交集
使用 Google Places API 获得 20 多个结果
如何使用 Google Places Autocomplete API iOS 保存以前搜索过的结果