Opening Google maps

Open Google maps

Search location and find route using Python script

This is a simple script to open Google maps using Python script.

I prefer this using code editor than Jupyter, as we can pass command-line arguments to the script.

Below is the script

In [ ]:
import webbrowser, sys, pyperclip, os, signal

if len(sys.argv) > 1:
    address = ''.join(sys.argv[1:])

    address = pyperclip.paste()

google_url = ''

url = "{}{}/{}".format(google_url, 'dir' if '/' in address else 'place', address)

os.kill(os.getppid(), signal.SIGHUP)  #this closes the terminal after running the script, comment this if you dont want that way

Say, you save this script as ''

For running this, 'python'

This '' is now read as a list of strings.

We can make use of this and pass location names to the script.

Like 'python Hyderabad Bengaluru'

This is read as ['', 'Hyderabad', 'Bengaluru']

Above script reads this and use them for showing in the Google maps.

I used a small if condition in the format script, so if you use '/' in the command-line it tries to find the route between these two locations or else just the location of it in Google maps.

Example for location : python hyderabad

Example for route : python hyderabad/bengaluru

Don't worry about the spacing, the script don't care.

Something particularly we want to search use comma. Like 'python jubilee hills, hyderabad / koramangala, bengaluru'

If you don't use any location in command-line, then it takes the text in the clipboard.

Styling cell, ignore this

In [1]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))