有人建议我发一个更详细的问题。提前感谢您的任何想法或指导。
基本上,我正在尝试从标准成功的Google地图搜索获得的API请求中获取所有相同的数据。
如果我在Google地图中搜索“拖拉机供应co brentwood tn”,我会得到这个丰富的结果,包含大量的业务细节和图像。 (请点击此链接查看我正在寻找的完整详情) google maps search result
如果我像这样进行谷歌API地理编码搜索(省略号代替https://因为我是论坛新手,而且还没有多个链接帖子的代表):
... maps.googleapis.com/maps/api/geocode/xml?address=TRACTOR+SUPPLY+COMPANY+(HQ)+ BRENTWOOD + TN&安培;键=的myKey
我收到了这个回复:
<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>OK</status>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Brentwood, TN, USA</formatted_address>
<address_component>
<long_name>Brentwood</long_name>
<short_name>Brentwood</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Williamson County</long_name>
<short_name>Williamson County</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Tennessee</long_name>
<short_name>TN</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>36.0331164</lat>
<lng>-86.7827772</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>35.9325590</lat>
<lng>-86.8698999</lng>
</southwest>
<northeast>
<lat>36.0447090</lat>
<lng>-86.6868770</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>35.9325590</lat>
<lng>-86.8698999</lng>
</southwest>
<northeast>
<lat>36.0447090</lat>
<lng>-86.6868770</lng>
</northeast>
</bounds>
</geometry>
<partial_match>true</partial_match>
<place_id>ChIJ41xJuq57ZIgRkN_2gzhAfTU</place_id>
</result>
</GeocodeResponse>
其中有一些相同的数据,但不是全部。它还提供“胎盘”。所以,如果我拉出来并根据这样的地方做一个“细节”搜索:
... maps.googleapis.com/maps/api/place/details/xml?placeid=ChIJ41xJuq57ZIgRkN_2gzhAfTU&key=mykey
我得到的结果似乎是使用通用的placeid而不是该公司特有的东西:
<?xml version="1.0" encoding="UTF-8"?>
<PlaceDetailsResponse>
<status>OK</status>
<result>
<name>Brentwood</name>
<vicinity>Brentwood</vicinity>
<type>locality</type>
<type>political</type>
<formatted_address>Brentwood, TN, USA</formatted_address>
<address_component>
<long_name>Brentwood</long_name>
<short_name>Brentwood</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Williamson County</long_name>
<short_name>Williamson County</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Tennessee</long_name>
<short_name>TN</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>36.0331164</lat>
<lng>-86.7827772</lng>
</location>
<viewport>
<southwest>
<lat>35.9325590</lat>
<lng>-86.8698999</lng>
</southwest>
<northeast>
<lat>36.0447090</lat>
<lng>-86.6868770</lng>
</northeast>
</viewport>
</geometry>
<url>https://maps.google.com/?q=Brentwood,+TN,+USA&ftid=0x88647baeba495ce3:0x357d403883f6df90</url>
<icon>https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<reference>CnRvAAAA7imTJVU7NIR2ZHUHP72h0JegnJJsPWEJYswpzCe_UTTGRmcbEjFCC-it8-GKmaMJiIR_oNShYTUTWGrdJkwbmKws1JY8iX_yItYHaiiKuDLZRDfgF8mK0aACDfjfsVJzJFoJsTGHhrUQcD9KtzrvJBIQK5_0vxAqFpN-8xTs3XP5kxoUMQD0mUqBZ2sO8RLcL-Dkhf2ltn8</reference>
<id>667453c8f258729c704ec5ed39d0ab09e79e8cc6</id>
<adr_address><span class="locality">Brentwood</span>, <span class="region">TN</span>, <span class="country-name">USA</span></adr_address>
<place_id>ChIJ41xJuq57ZIgRkN_2gzhAfTU</place_id>
<scope>GOOGLE</scope>
</result>
</PlaceDetailsResponse>
此结果也不包含简单谷歌搜索的完整详细信息,甚至还包含文档所说的应由“详细信息”搜索产生的完整“详细信息”。
我也尝试使用地方API进行“textsearch”,如下所示:
... maps.googleapis.com/maps/api/place/textsearch/xml?query=TRACTOR+SUPPLY+COMPANY+(HQ)+ BRENTWOOD + TN&安培;键=的myKey
返回此内容:
<?xml version="1.0" encoding="UTF-8"?>
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Tractor Supply Company</name>
<type>point_of_interest</type>
<type>establishment</type>
<formatted_address>5401 Virginia Way, Brentwood, TN 37027, United States</formatted_address>
<geometry>
<location>
<lat>36.0322092</lat>
<lng>-86.8131363</lng>
</location>
</geometry>
<rating>3.4</rating>
<icon>https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png</icon>
<reference>CnRpAAAAqLzUG_q4XIngf8xF1dcx-Gofy-uBiBvvZJoLNFFQ1ZoQ83fWx_teRICg_Fbl2dfMd2i1U9pLwYpBFx2fNeB51Yvnb6emO_IaVf7_Ex7HqvbgoawTy06aMuD3H3rr6BITfHg0Qr31a9Fkn2-k3S_UKBIQscPj4YrbojkF7Fw3j8RgMxoUcpgyXPXincWiPyuoTRA6XU9TCJU</reference>
<id>1733e3c88f2446c3502000eae8ddf94e63b89602</id>
<opening_hours>
<open_now>true</open_now>
</opening_hours>
<photo>
<photo_reference>CoQBdwAAANoj0c9wy5uab1aCuip5nlxW1XAU_2wei_XeWUNUM4Cuv3sGTSsyA4zb0qN0OKkaJOAZM7BCJgf4YPtyCvQv4h41UNsxNeT4yOppArK-JOzpOKrJT_WMcbS8c7ormj9-F_Mz5JOLPVV6bWEQKl6gqKvFGVLOpTxP0SEO50TyKffoEhDG0h4EX3lNzLIe9rFOv6nPGhRychAj_sRndkuzHC-cHVgH_wSwEw</photo_reference>
<width>3264</width>
<height>2448</height>
<html_attribution><a href="https://maps.google.com/maps/contrib/102180476513775764202/photos">Jeremy Haggard</a></html_attribution>
</photo>
<price_level>2</price_level>
<place_id>ChIJL-npOFt7ZIgRgaOcl-AVuDU</place_id>
</result>
</PlaceSearchResponse>
同样,不是简单的谷歌地图搜索提供的完整数据集,甚至是我们应该从“详细”搜索中获得的数据。
那么有没有办法格式化API请求甚至多个API请求,这将允许我检索所有这些相同的数据?我当然可以用不同的方式格式化搜索数据(例如全部小写或没有标点符号等),但我已经尝试过了,这似乎并不重要。我应该在查询中添加一个参数吗?
我已经有一段时间了,我被困住了。非常感谢任何帮助。
更新:在geocodezip发表评论后,我尝试了一个略有不同的网址(我希望这是你试图告诉我的)。我首先使用上面相同的术语进行地理编码搜索以获得lat&amp; long,然后我使用lat&amp; long进行了地方API搜索,如下所示:... // maps.googleapis.com/maps /api/place/nearbysearch/xml?location=35.9325590,-86.8698999&radius=5000&name=TRACTOR|SUPPLY&key=mykey
尝试了几种不同的参数组合。结果好坏参半但基本上比以前差。从来没有在谷歌地图搜索中轻松提供的单一结果,而且通常网络太宽,结果太多。这是一个例子:
<?xml version="1.0" encoding="UTF-8"?>
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Tractor Supply Co.</name>
<vicinity>1101 Hillview Lane, Franklin</vicinity>
<type>hardware_store</type>
<type>home_goods_store</type>
<type>store</type>
<type>point_of_interest</type>
<type>establishment</type>
<geometry>
<location>
<lat>35.8907643</lat>
<lng>-86.8778121</lng>
</location>
</geometry>
<rating>4.5</rating>
<icon>https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png</icon>
<reference>CnRlAAAAj6SHHs-lw-RGVupH8Pvd5TH0UxslEwrZfqWt3jlWQoXfQF3F4QwtO6dRHHluYMCmTnUbZkjlb_EjxYdh1xxuKQm1t_HKEb6GFkd5O4etE6IVjVjeC90QsOtCTFi5Y3RkWPbY_bFJxveVulTZ6REhKBIQ311Kf-nQw6elbAclygFtCRoU2ZtPK0g5Arq7CZQ4Yrz_eHJvErc</reference>
<id>fbcd6594faab6531269569c223a846280cf5694e</id>
<opening_hours>
<open_now>true</open_now>
</opening_hours>
<photo>
<photo_reference>CoQBcwAAAAMQPyHJ4tzPHuVwirxpOEdNRduW3YV3qBHKtDPW9TnUWsPx0dyOP9VbUt3Xi2X5iDpiU8KAcpECr6BgI4er67LHi6vIAPPdvKnEVQxEoa0xf7-bWYJC0I8XvOr-pWE-wXth-zxNNrehDhEZ3avD6CCIycxcRMaSt0sbgIAnKf2OEhAkGkj4V_HFnnEsmgXu7xmWGhRqNCKGqYOikAH2bzLG6QC8O6Feew</photo_reference>
<width>348</width>
<height>348</height>
<html_attribution><a href="https://maps.google.com/maps/contrib/117785023973427282224/photos">Mark Grubb</a></html_attribution>
</photo>
<price_level>2</price_level>
<place_id>ChIJF4g295N_ZIgRWFMbRGsSfRc</place_id>
<scope>GOOGLE</scope>
</result>
</PlaceSearchResponse>
答案 0 :(得分:0)
地理编码结果和地点搜索的placeId不同。对于地点的结果,请使用从路线服务中检索到的placeId。
您正在执行详细信息请求(地理编码器响应中的place_id):
<place_id>ChIJ41xJuq57ZIgRkN_2gzhAfTU</place_id>
而是使用(Places API响应中的place_id):
<place_id>ChIJF4g295N_ZIgRWFMbRGsSfRc</place_id>