This is Api client is made by me for simple and quick integration. It will find places in a location such as parks, malls, hotels and much more. This provides methods to find the places based on place id and search places with with their some names.
- Make a project on Google Cloud Platfrom. Be sure to enable billing feature. It won't cost you untill you make thousand of requests. Then enable GEOCODING API and PLACES API in your project section.
- First run the
requirements.txt
to install the dependencies by the below code:-python3 install -r requirements.txt
- Enter your own api key in GOOGLE_API_KEY in python code.
- That's all, Hurray.
- First make a object of the api class. Give a default address. You can add the For example :-
client = GoogleMapsClient(api_key=GOOGLE_API_KEY,default_address="Enter_the_desired_location")
- This Api provides two method:
- 2.1 Search places in a location
- 2.2 Find a place using the Place ID. - Using the Search places. Basic syntax :-
client.search(keyword="ANYTHING",location="ANY",radius="")
It has three parameters:
-keyword:It can be anything that you want to search like mall, hotel , restaurant, park and much more.
-location: It can be anywhere. It is optional as it will search places in default_address.
-radius: It is the radius of area to search. It is in meters and the default value is set as 1000. You can change it by giving value in parameter.
sample example:-client.search(keyword="mall",location="faridabad",radius=3000)
- Using the Place method. Basic syntax :-
client.detail(self, place_id="ENTER_THE_PLACE_ID", fields=[ENTER THE FIELD YOU WANT TO FIND])
Currently the google provide four fields:- "name", "rating", "formatted_phone_number". You can use anyone. Dont pass the field parameter if you want all the parameters as it is already intialized in the code
sample example for all field:-client.detail(place_id="ChIJqW9BqQe6j4AR0il4CC315_s")
sample example for particular field:-client.detail(place_id="ChIJqW9BqQe6j4AR0il4CC315_s", fields=["name"])
Note :- This Api will give the json response.
It uses the two Api to fetch the data and process it.
You can use this code anywhere without any permission