2012-12-21 4 views
2

Google Nearby Search에서 장소를 가져 오는 데 다음 코드를 사용했습니다.Google 주변 검색과의 거리

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에서 이름, 주소, 위도, 경도를 검색했다. 나는 또한 그 장소의 거리가 필요하다. 그러나 그것을 발견 할 수 없다. 누군가 제발 도와주세요.

답변

0

당신은 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> 
...... 
+0

감사합니다를 회신 선생님을 위해. 그러나 나는 이것을 보았다. 출발지와 목적지가 필요합니다. – ToothLess

+0

예. 현재 주소를 알아낼 수 있어야합니다. 목적지의 경우 Google 위치 URL에서 검색 할 수 있어야합니다. 따라서 Google 지역 정보 API에서 검색 한 각 결과에 대해 destination_address 매개 변수로 사용해야합니다. – Rudy