Python Forum
Search "Places near by me" or "where am I" in google maps
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search "Places near by me" or "where am I" in google maps
#1
Hi, is it possible to search the results "where am I" or "places nearby me" using google API in python
Right now mentioned below Python code is searching the place only.
like when I am mentioning "Hotel in California" then places list has been mentioned in the python shell
But while searching the query "where am i" it does not give any list.
# importing required modules 
import requests, json 
  
# enter your api key here 
api_key = 'Your_API_key'
  
# url variable store url 
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?"
  
# The text string on which to search 
query = input('Search query: ') 
  
# get method of requests module 
# return response object 
r = requests.get(url + 'query=' + query +
                        '&key=' + api_key) 
  
# json method of response object convert 
#  json format data into python format data 
x = r.json() 
  
# now x contains list of nested dictionaries 
# we know dictionary contain key value pair 
# store the value of result key in variable y 
y = x['results'] 
  
# keep looping upto lenght of y 
for i in range(len(y)): 
      
    # Print value corresponding to the 
    # 'name' key at the ith index of y 
    print(y[i]['name'])
Note: Right now, I am only using Google maps API, Do I have to use any other API also?

Your leads on this will be a great help
Reply
#2
(Feb-07-2019, 01:38 PM)barry76 Wrote: Hi, is it possible to search the results "where am I" or "places nearby me" using google API in python
That depend of what doc for API say,this may be for mobile(GPS on).
A little rewrite to make it look better,with f-string and get rite of range(len(y)).
import requests

api_key = 'your_api_key'
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?"
query = 'Hotel in California'
response = requests.get(f'{url}query={query}&key={api_key}')
json_data = response.json()
for place json_data['results']):
    print(place['name'])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with nested maps Unkovic 10 1,345 Nov-01-2023, 03:45 PM
Last Post: Unkovic
  Calculate the Euler Number with more decimal places Pedroski55 10 4,490 Oct-31-2021, 04:45 AM
Last Post: Pedroski55
  Not rounding to desired decimal places? pprod 2 2,542 Mar-05-2021, 11:11 AM
Last Post: pprod
  Can I format decimal places by column with a dictionary? Mark17 2 2,548 Dec-28-2020, 10:13 PM
Last Post: Mark17
  how to import files in Google Collab wihout downloading them to PC and to Google Disk sveto4ka 9 3,866 Jun-03-2020, 12:40 PM
Last Post: sveto4ka
  Best way to map trajectory data on Google Maps Gduffley 1 2,669 Feb-05-2020, 12:36 AM
Last Post: scidam
  Can't visualize maps using Gmaps mPlummers 0 3,545 Sep-11-2019, 02:38 PM
Last Post: mPlummers
  Non-Geographic Heat Maps JackValadez 0 2,085 Oct-17-2018, 06:03 PM
Last Post: JackValadez
  Can I search from Python, automatically and randomly generated keywords in Google? xX_Prophit_Xx 0 2,295 Sep-07-2018, 04:43 PM
Last Post: xX_Prophit_Xx
  How get attributes of maps from loop statement LB_994 3 3,153 Aug-21-2018, 03:24 PM
Last Post: LB_994

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020