Search code examples
python-3.xgoogle-apigoogle-places-api

Find specific locations closest to a given position


I want to find closest specific location of a place like closest hospital or closest police station or etc to a given position. I saw this code in one of the questions but i don't get any response to this code.

from googleplaces import GooglePlaces, types, lang

google_places = GooglePlaces(API KEY)

query_result = google_places.nearby_search(
        location='London, England',
        radius=20000, types=[types.TYPE_FOOD])

print (query_result.html_attributions)

I want a working code that helps me to find these closest community places like police stations, banks, hospitals to a given position. Thanks!


Solution

  • This code worked for me,

    from googleplaces import GooglePlaces, types, lang
    
    google_places = GooglePlaces("AIzaSyCNLxPxFmG3kfrALBUkRFb_R5UdemVnqqQ")
    
    query_result = google_places.nearby_search(
            location="51.529972 -0.127676",
            radius=20000, types=[types.TYPE_RESTAURANT])
    
    #if query_result.has_attributions:
    print (query_result.places)