Hi. I need a Python program for a presentation. I need to use Google Place API.
ID: 3714032 • Letter: H
Question
Hi. I need a Python program for a presentation.
I need to use Google Place API. The program can have the user pins on the map. When user type in the word regarding to the pin, the program can show the location nears him.
For an example, users can pin on the map for a location where flu patients are found. So when other users type flu in the search box, it will return the nearest location that has flu patients.
Also, when user search a specific place the program will return the place's picture.
Please use Tkinter for the GUI.
It can be just few functions instead of entire program.
I'm using Python 3.
Explanation / Answer
from googlemaps import convert
def places(client, query, location=None, radius=None, language=None):
//
Places search.
:param query: The text string on which to search, for example: "restaurant".
:type query: string
:param location: The latitude/longitude value for which you wish to obtain the
closest, human-readable address.
:type location: string, dict, list, or tuple
:param radius: Distance in meters within which to bias results.
:type radius: int
:param language: The language in which to return results.
:type langauge: string
//
return _places(client, "text", query=query, location=location,
radius=radius
)
def places_nearby(client, location=None, radius=None, keyword=None,
language=None):
if not location and not page_token:
raise ValueError("either a location or page_token arg is required")
if rank_by == "distance":
if not (keyword or name or type):
raise ValueError("either a keyword, name, or type arg is required "
"when rank_by is set to distance")
elif radius is not None:
raise ValueError("radius cannot be specified when rank_by is set to "
"distance")
return _places(client, "nearby", location=location, radius=radius,
keyword=keyword, language=language, min_price=min_price,
max_price=max_price, name=name, open_now=open_now,
rank_by=rank_by, type=type, page_token=page_token)
def _places(client, url_part, query=None, location=None, radius=None,
keyword=None, language=None, min_price=0, max_price=4, name=None,
open_now=False, rank_by=None, type=None, region=None, page_token=None):
"""
Internal handler for ``places``, ``places_nearby``, and ``places_radar``.
See each method's docs for arg details.
"""
params = {"minprice": min_price, "maxprice": max_price}
if query:
params["query"] = query
if location:
params["location"] = convert.latlng(location)
if radius:
params["radius"] = radius
if keyword:
params["keyword"] = keyword
if language:
params["language"] = language
if name:
params["name"] = convert.join_list(" ", name)
if open_now:
params["opennow"] = "true"
if rank_by:
params["rankby"] = rank_by
if type:
params["type"] = type
if region:
params["region"] = region
if page_token:
params["pagetoken"] = page_token
url = "/maps/api/place/%ssearch/json" % url_part
return client._request(url, params)
def place(client, place_id, language=None):
"""
Comprehensive details for an individual place.
:param place_id: A textual identifier that uniquely identifies a place,
returned from a Places search.
:type place_id: string
:param language: The language in which to return results.
:type langauge: string
:rtype: result dict with the following keys:
result: dict containing place details
html_attributions: set of attributions which must be displayed
"""
params = {"placeid": place_id}
if language:
params["language"] = language
return client._request("/maps/api/place/details/json", params)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.