Python 3 Script to Generate Google Maps HTML Iframe Embed Code From Address in Terminal
234 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-script-to-generate-google-maps-html-iframe-embed-code-from-address-in-terminal/
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you how to
0:04
generate a Google maps I frame uh where
0:08
you can actually take the screenshot of
0:10
a specific location and this Python
0:13
script will actually return the I frame
0:15
for you so let me just show you the
0:16
example so this is actually our Python
0:18
script let me go to the terminal and I
0:21
run the script right here so as soon as
0:24
I run the script you will see it will
0:25
return me this if and I can simply copy
0:30
this and then create a simple index html
0:34
file and
0:37
uh then I can simply paste this I frame
0:42
and as soon as you paste this I frame it
0:44
will return this I frame and if I open
0:48
this in the browser so it actually looks
0:51
like this it will have the actual
0:53
address that you typed you can see it
0:56
will have a marker right here and
0:58
whenever you hover onto this you will
0:59
see the address which is Tajell you can
1:02
see that so you can even zoom in inside
1:05
the map right here so this is really
1:08
useful uh what this Python script is
1:11
doing it is actually returning you the
1:13
iframe of the Google map
1:16
uh location so here you just need to
1:19
fill out the location so I basically
1:22
fill out this location Taj Mal India so
1:25
I can even change this location let's
1:27
suppose I enter any
1:31
address so let's suppose I enter a
1:33
different address right here so once
1:35
again if you run this Python script it
1:38
will once again return you this iframe
1:41
code here so this iframe code you can
1:44
again copy this and paste
1:51
it so this time if you see it will
1:57
change and if you see in the browser
2:00
here you will see now it has a different
2:03
location so for this you don't require
2:06
any API key i will show you how to embed
2:09
the Google map inside iframe and so this
2:12
Python script will activate
2:14
automatically do this for you so right
2:17
here we simply need to define a custom
2:19
function so just create a simple app py
2:22
file and here you specify your location
2:26
and
2:27
uh so you can just write any location
2:30
here let's suppose I say
2:33
Sydney and then we put the I frame here
2:36
and we call a function which
2:38
is
2:40
generate Google maps I frame and we
2:44
actually pass this
2:46
location and then we actually print out
2:49
the I frame URL so now we just need to
2:51
define this uh function which
2:55
is generate Google maps I frame and
2:59
inside this
3:00
function it can even take uh the width
3:04
as well so by default the width will be
3:07
600 and the height will be 450 and the
3:11
zoom level will be 14 so you can
3:13
manipulate all these factors inside this
3:16
function so now inside this function
3:19
right here we can
3:21
actually need to define a function which
3:24
will a variable base URL so now to embed
3:28
the Google map in the iframe we have
3:30
this URL Google so all this script is
3:34
given in the description of this video
3:35
guys you can actually copy the script
3:38
the link is given in the
3:40
description so we are using the Google
3:42
maps embed
3:44
API so this is actually the URL right
3:48
here
3:50
uh https
3:55
www.google.com/map/imbed version one
3:56
place so now we define this and after
4:00
that we now need
4:03
to replace the location right here so
4:06
encoded
4:08
location and whatever is the location
4:10
that you
4:11
passed we simply replace
4:17
it like
4:19
this and for this you don't need to pass
4:22
any API key and then we define our
4:26
iframe URL which will be you can see
4:29
that we dynamically embedding this
4:32
inside this maps.google.com/maps
4:34
google.com/maps question mark Q is equal
4:37
to and then here we have embedded this
4:40
encoded location and whatever is the
4:42
zoom
4:43
level and that's
4:47
all so after that we actually return the
4:52
I frame code which will be returned from
4:57
this function so this is your I frame
4:59
code right here
5:05
so let me just show you the overall
5:07
script right here the link is given in
5:09
the description guys you can copy this
5:10
script so here we actually define the
5:13
base URL then we provide the encoded
5:16
location and then inside the iframe URL
5:19
we are using this Google maps embed API
5:22
https mapaps.google.com and here we
5:25
specify our location and the zoom level
5:29
and then lastly in the I frame code we
5:32
are specifying the I frame tag we are
5:34
putting the width the height and all
5:38
these lazy loading allow full
5:41
screen so here we can change this
5:44
location so I can change it
5:49
Sydney so once again I go to the
5:52
terminal and I run the script
5:56
so it will give you this I frame URL so
6:00
you can simply copy this and uh inside
6:03
your index html you can paste
6:09
this and if you serve this
6:14
project so it will actually show you the
6:17
screenshot of the Google map right here
6:19
with that location so in this easy way
6:21
guys you can embed your Google maps
6:23
directly inside the browser using this
6:25
Python script it will return you the
6:27
iframe code here of the location that
6:29
you type in the Python script the link
6:32
is given in the description if you need
6:33
to copy the full source code and also
6:36
check out my website freemediattools.com
6:40
uh which contains thousands of tools
#Scripting Languages
#Software