Capture embedded google map image with Python without using a browser

前端 未结 8 1134
心在旅途
心在旅途 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 19:10

    Rather than trying to use the embed link, you should go directly to the Google API to get images as static graphics. Here's the link to the Google Maps static image API - it looks like you can just pass in the long/lat parameters in the URL just as you do for the normal embeddable one. For example:

    http://maps.googleapis.com/maps/api/staticmap?center=-30.027489,-51.229248&size=600x600&zoom=14&sensor=false
    

    gives you an 600x600 street-level overview centered on the co-ordinates you give above, which seems to be Porto Alegre in Brazil. Now you can use urlopen and PIL as Ned suggests:

    from cStringIO import StringIO
    import Image
    import urllib
    
    url = "http://maps.googleapis.com/maps/api/staticmap?center=-30.027489,-51.229248&size=800x800&zoom=14&sensor=false"
    buffer = StringIO(urllib.urlopen(url).read())
    image = Image.open(buffer)
    

提交回复
热议问题