Google streetview static api

来源:互联网 发布:微商三级分销系统源码 编辑:程序博客网 时间:2024/04/29 03:47

http://jamiethompson.co.uk/web/2010/05/15/google-streetview-static-api/
May 15th, 2010

It is possible to extract both thumbnails and higher resolution images (tiles) from the Google Streetview service through an unpublished, undocumented API which I will document below. Google have not publicly released this API, but nor have they sought to secure or even obfuscate it in any way. To me, this is about as open an invitation as it gets.

Thumbnails(TheEasyBit)

You might have noticed that more often than not, when viewing a location on Google Maps nowadays you get a little Streetview thumbnail linking to the appropriate location on Google Streetview. If you’ve ever wondered if you could get static streetview imaging out Google for your own use then read on.

 

Google Maps Showing Streetview Thumbnail

Inspection of the image source reveals something quite surprising:
http://cbk0.google.com/cbk?output=thumbnail&w=90&h=68&ll=51.494966,-0.146674

http://cbk0.google.com/cbk?output=thumbnail&w=[WIDTH]&h=[HEIGHT]&ll=[LAT,LNG]

Not exactly cryptic is it. We have a width, a height and a lat/lng pair. Playing with the values of width and height you will find the maximum dimensions available are 416×208 pixels, giving you a full, albeit small, 360 degree panorama of your desired location. You can play with the coordinates too but specifying a location without a streetview panorama will result in a 404 error.

IthinkI’mpanoid…

Each Streetview panorama is uniquely identified by an panoid. I’m pretty sure this is a timecode hash but I haven’t looked into it any further. For the purposes of fetching Streetview images the only important thing to consider is that these are unique ids.

If you’re like me, you’ve been looking at the example above and wondering what other output types there are besides ‘thumbnail’. One of the other options is ‘xml’, which returns some handy metadata for a given location. You can use this data to determine if there is a streetview panorama available at your chosen location.

http://cbk0.google.com/cbk?output=xml&ll=[LAT,LNG]

Example:
http://cbk0.google.com/cbk?output=xml&ll=51.494966,-0.146674

01<panorama>
02<data_properties image_width="13312" image_height="6656" tile_width="512" tile_height="512" pano_id="sLaiF6Jex7mJmNol7tdOoA" num_zoom_levels="3" lat="51.495090" lng="-0.146971" original_lat="51.495098" original_lng="-0.147000">
03<copyright>© 2010 Google</copyright>
04<text>Eccleston Pl</text>
05<region>London, England</region>
06<country>United Kingdom</country>
07<data_flag>1</data_flag>
08</data_properties>
09<projection_properties projection_type="spherical" pano_yaw_deg="201.78" tilt_yaw_deg="92.06" tilt_pitch_deg="1.75"/>
10<annotation_properties>
11<link yaw_deg="204.7" pano_id="CeutxcyB2V74lfN_fJwRww" road_argb="0x80ffffff">
12<link_text>Eccleston Pl</link_text>
13</link>
14<link yaw_deg="24.7" pano_id="t_mnKSugTLrQTEnJplXQ3A" road_argb="0x80ffffff">
15<link_text>Eccleston Pl</link_text>
16</link>
17</annotation_properties>
18</panorama>

This returns a lot of data, but for now we’ll simply concentrate on the panoidvalues. Generally there will be three panoids. One as an attribute of thedata_properties element and two as the attributes of the two link elements of theannotation_properties element. As far as I can tell the supplemental two panoids relate to the previous and next panorama on the route.

So in this example we end up with a main panoid of “sLaiF6Jex7mJmNol7tdOoA”

Finally we can plug this value into the thumbnail url as follows:

http://cbk0.google.com/cbk?output=thumbnail&w=[WIDTH]&h=[HEIGHT]&panoid=[PID]

http://cbk0.google.com/cbk?output=thumbnail&w=416&h=208&panoid=sLaiF6Jex7mJmNol7tdOoA

Notice how we end up with exactly the same panorama, but at a different offset.

With a little extra work, tying this into the Open Postcode Geocoding API, I came up with a nice little wrapper around this accepting a UK postcode and directly returning the corresponding panorama thumbnail. I’ve added this to my geo webservice and it is callable as follows:

http://geo.jamiethompson.co.uk/streetview/[POSTCODE]_[WIDTH]x[HEIGHT].jpg

Example
http://geo.jamiethompson.co.uk/streetview/SW1W9TQ_416×208.jpg

Thehighdetailtiles

So, you probably noticed some info relating to tiles in the xml data in the previous example. It’s possible to fetch a set of 512 pixel square tiles at various zoom levels for a given panorama using the following request.

http://cbk0.google.com/cbk?output=tile&panoid=[PID]&zoom=[ZOOM]&x=[X]&y=[Y]

[X] and [Y] relate to the horizontal and vertical tile positions, while [ZOOM] relates to the zoom level. If the XML data is to be believed there are 3 zoom levels, but I have found there to be 5. The number of X and Y positions increases with each zoom level. These are zero based.

Zoom Level 0:
Example of Streetview Tile Zoom Level 0
Single Tile – X=0, Y=0

Zoom Level 1:
Example of Streetview Tile Zoom Level 1
Tile 1 – X=0, Y=0 Tile 2 – X=1, Y=0

Zoom Level 2
Example of Streetview Tile Zoom Level 2
4 X positions (0-3), 2 Y positions (0-1)

Zoom Level 3
Example of Streetview Tile Zoom Level 3
6 X positions (0-5), 3 Y positions (0-2)

Zoom Level 4
Example of Streetview Tile Zoom Level 4
13 X positions (0-12), 7 Y positions (0-6)

Zoom Level 5
Example of Streetview Tile Zoom Level 5
26 X positions (0-25), 13 Y positions (0-12)

Demo

I’ve put together a very quick and dirty demo page that displays the tiles re-assembled for any given UK postcode. Be warned, at zoom level 5 this will download 338 512×512 pixel tiles, roughly 7-8MB.


Google Streetview Tile Viewer Demo

demo:

http://geo.jamiethompson.co.uk/streetview_tiles.php?postcode=SW1W+9TQ&zoom=3

 

台北101

http://cbk0.google.com/cbk?output=thumbnail&w=200&h=100&ll=25.033661,121.565201

原创粉丝点击