Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:10:20+00:00 2026-05-26T12:10:20+00:00

I have noticed that, from Google Maps page, you can get an embed link

  • 0

I have noticed that, from Google Maps page, you can get an “embed” link to put inside an iframe and load the map in a browser. (no news here)

The image size can be adjusted to be very large, so I am interested in getting som big images as single .PNGs.

More specifically, I would like to define a rectangular area from a bounding box (upper-right and lower-left coordinates), and get the corresponding image, with an appropriate zoom factor.

But my question is: How can I use Python to get the “pixel content” of this map as an image object?

(My rationale is: if the browser can get and render such image content, then Python should be capable of doing it, too).

EDIT: this is the content of the HTML file that shows my sample map:

<iframe 
    width="2000"
    height="1500"
    frameborder="0"
    scrolling="yes"
    marginheight="0"
    marginwidth="0"
    src="http://maps.google.com.br/maps?hl=pt-BR&amp;ll=-30.027489,-51.229248&amp;spn=1.783415,2.745209&amp;z=10&amp;output=embed"/>

EDIT: I did as suggested by Ned Batchelder, and read the content of an urllib.urlopen() call using the src address taken from the iframe above. The result was a lot of javascript code, which I think has to do with the Google Maps JavaScript API. So, the question lingers: how could I do some useful stuff from all this stuff in Python in order to get the map image?

EDIT: this link appears to contain some pretty relevant info on how Google Maps tiles their maps:
http://www.codeproject.com/KB/scrapbook/googlemap.aspx

also:
http://econym.org.uk/gmap/howitworks.htm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:10:21+00:00Added an answer on May 26, 2026 at 12:10 pm

    I thank for all the answers. I ended up solving the problem another way, using Google Maps Static API and some formulas to convert from Coordinate space to Pixel space, so that I can get precise images that “stitch” nicely together.

    For anyone interested, here is the code. If it helps someone, please comment!

    =============================

    import Image, urllib, StringIO
    from math import log, exp, tan, atan, pi, ceil
    
    EARTH_RADIUS = 6378137
    EQUATOR_CIRCUMFERENCE = 2 * pi * EARTH_RADIUS
    INITIAL_RESOLUTION = EQUATOR_CIRCUMFERENCE / 256.0
    ORIGIN_SHIFT = EQUATOR_CIRCUMFERENCE / 2.0
    
    def latlontopixels(lat, lon, zoom):
        mx = (lon * ORIGIN_SHIFT) / 180.0
        my = log(tan((90 + lat) * pi/360.0))/(pi/180.0)
        my = (my * ORIGIN_SHIFT) /180.0
        res = INITIAL_RESOLUTION / (2**zoom)
        px = (mx + ORIGIN_SHIFT) / res
        py = (my + ORIGIN_SHIFT) / res
        return px, py
    
    def pixelstolatlon(px, py, zoom):
        res = INITIAL_RESOLUTION / (2**zoom)
        mx = px * res - ORIGIN_SHIFT
        my = py * res - ORIGIN_SHIFT
        lat = (my / ORIGIN_SHIFT) * 180.0
        lat = 180 / pi * (2*atan(exp(lat*pi/180.0)) - pi/2.0)
        lon = (mx / ORIGIN_SHIFT) * 180.0
        return lat, lon
    
    ############################################
    
    # a neighbourhood in Lajeado, Brazil:
    
    upperleft =  '-29.44,-52.0'  
    lowerright = '-29.45,-51.98'
    
    zoom = 18   # be careful not to get too many images!
    
    ############################################
    
    ullat, ullon = map(float, upperleft.split(','))
    lrlat, lrlon = map(float, lowerright.split(','))
    
    # Set some important parameters
    scale = 1
    maxsize = 640
    
    # convert all these coordinates to pixels
    ulx, uly = latlontopixels(ullat, ullon, zoom)
    lrx, lry = latlontopixels(lrlat, lrlon, zoom)
    
    # calculate total pixel dimensions of final image
    dx, dy = lrx - ulx, uly - lry
    
    # calculate rows and columns
    cols, rows = int(ceil(dx/maxsize)), int(ceil(dy/maxsize))
    
    # calculate pixel dimensions of each small image
    bottom = 120
    largura = int(ceil(dx/cols))
    altura = int(ceil(dy/rows))
    alturaplus = altura + bottom
    
    
    final = Image.new("RGB", (int(dx), int(dy)))
    for x in range(cols):
        for y in range(rows):
            dxn = largura * (0.5 + x)
            dyn = altura * (0.5 + y)
            latn, lonn = pixelstolatlon(ulx + dxn, uly - dyn - bottom/2, zoom)
            position = ','.join((str(latn), str(lonn)))
            print x, y, position
            urlparams = urllib.urlencode({'center': position,
                                          'zoom': str(zoom),
                                          'size': '%dx%d' % (largura, alturaplus),
                                          'maptype': 'satellite',
                                          'sensor': 'false',
                                          'scale': scale})
            url = 'http://maps.google.com/maps/api/staticmap?' + urlparams
            f=urllib.urlopen(url)
            im=Image.open(StringIO.StringIO(f.read()))
            final.paste(im, (int(x*largura), int(y*altura)))
    final.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a Google Maps API (JavaScript) developer. I have noticed that Google uses
I'm trying to fetch some HTML from various blogs and have noticed that different
Ever noticed that when you go to maps.google.com and do a search (say, car
I have noticed that some json queries, particularly in google services, return a peculiar
I noticed a blog post from Google that mentions the ability to paste images
I noticed that i have not being getting traffic via google organic searches. I
I have just been implementing a google map, that pulls data from the yelp
I have a web app that uses Google Maps API v3. I have it
Last time I have noticed problem with google maps cluster. I use gmaps4rails plugin
I have a program that gathers information from referring urls. Today i noticed that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.