Capture embedded google map image with Python without using a browser

前端 未结 8 1110
心在旅途
心在旅途 2020-12-04 18:57

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

8条回答
  •  暖寄归人
    2020-12-04 19:16

    This is Daniel Roseman's answer for people that use python 3.x:

    • Assuming you got already Google Maps static image API

    Python 3.x code:

    from io import BytesIO
    from PIL import Image
    from urllib import request
    import matplotlib.pyplot as plt # this is if you want to plot the map using pyplot
    
    url = "http://maps.googleapis.com/maps/api/staticmap?center=-30.027489,-51.229248&size=800x800&zoom=14&sensor=false"
    
    buffer = BytesIO(request.urlopen(url).read())
    image = Image.open(buffer)
    
    # Show Using PIL
    image.show()
    
    # Or using pyplot
    plt.imshow(image)
    plt.show()
    

提交回复
热议问题