【问题标题】:Distance from Google Nearby Search与 Google 附近搜索的距离
【发布时间】:2012-12-21 07:17:29
【问题描述】:

我尝试使用以下代码从Google Nearby Search 获取位置。

from googleplaces import GooglePlaces, types, lang

YOUR_API_KEY = 'AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI'

google_places = GooglePlaces(YOUR_API_KEY)

query_result = google_places.query(
        location='London, England', keyword='Fish and Chips',
        radius=20000, types=[types.TYPE_FOOD])

if query_result.has_attributions:
    print query_result.html_attributions


for place in query_result.places:
    # Returned places from a query are place summaries.
    print place.name
    print place.geo_location
    print place.reference

    # The following method has to make a further API call.
    place.get_details()
    # Referencing any of the attributes below, prior to making a call to
    # get_details() will raise a googleplaces.GooglePlacesAttributeError.
    print place.details # A dict matching the JSON response from Google.
    print place.local_phone_number
    print place.international_phone_number
    print place.website
    print place.url

我得到了给定位置和半径的地点列表的 json 输出。我从 json 中检索了名称、地址、纬度、经度。我也需要那个地方的距离,但是找不到。有人请帮忙。

【问题讨论】:

    标签: python google-maps-api-3


    【解决方案1】:

    您可以使用Google Distance Matrix API.

    它会返回这样的输出:

    <?xml version="1.0" encoding="UTF-8"?> 
    <DistanceMatrixResponse> 
    <status>OK</status> 
    <origin_address>Vancouver, BC, Canada</origin_address> 
    <origin_address>Seattle, État de Washington, États-Unis</origin_address> 
    <destination_address>San Francisco, Californie, États-Unis</destination_address> 
    <destination_address>Victoria, BC, Canada</destination_address> 
    <row> 
     <element> 
      <status>OK</status> 
      <duration> 
      <value>340110</value> 
      <text>3 jours 22 heures</text> 
      </duration> 
      <distance> 
       <value>1734542</value> 
       <text>1 735 km</text> 
      </distance> 
     </element>
     ...... 
    

    【讨论】:

    • 谢谢先生的回复。但我看过这个。它需要起点和终点吗?
    • 是的。你应该能够得到你现在的地址。对于目的地,您应该能够从您的谷歌地点 URL 中检索。因此,对于您从 Google Place API 检索到的每个结果,您应该将其用作参数作为目的地地址。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 2014-11-06
    相关资源
    最近更新 更多