Wednesday, January 26, 2011

Decoding Google Maps Street View Image

Google Maps is awesome and when Google Maps Street View came out I was pretty amazed. But, I don't want to see the street view in flash, I just want to see the street view image. I did some research and it looks like I am not alone, someone already figured out how to extract image tiles from the Google Streetview service. Well, with little repetition, let's expand on this below.

Let's start with some Geo Coordinates of some random location, or maybe let's just use a Boston location shown on the StreetView Simple Example from Google Maps. It gives us a location (2 Yawkey Way, Boston, Massachusetts) but no Geo Coordinates. Well, not too long ago Google added reverse geocoding to their web services so we can easily figure out the latitude and longitude coordinates from an address:

http://maps.googleapis.com/maps/api/geocode/xml?address=2+Yawkey+Way,+Boston,+MA&sensor=true

and it gives us:

[sourcecode language="xml"]
<location>
<lat>42.3467972</lat>
<lng>-71.0988861</lng>
</location>
[/sourcecode]


Next, we need something called a pano id to generate our tiled image, and to get that we use the coordinates above in this call:

http://cbk0.google.com/cbk?output=xml&ll=42.3467972,-71.0988861

which gives us:

[sourcecode language="xml"]
<data_properties image_width="13312" image_height="6656" tile_width="512" tile_height="512" pano_id="yerN9BDKmxDjHiavUjrDNQ" num_zoom_levels="3" lat="42.346814" lng="-71.098936" original_lat="42.346814" original_lng="-71.098932">
[/sourcecode]

So, now that we have this panorama id (pano_id="yerN9BDKmxDjHiavUjrDNQ") and the available zoom levels (num_zoom_levels="3" ) we can create the appropriate grid of tiles that will compose a 360 street view image of our address. Since the zoom level is 3, our grid will compose of 6 X positions (0-5) and 3 Y positions (0-2) which together will build our big image. The url format looks like this:

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

If the zoom level was 1, the x and y would both be 0, and our image would look like this:

http://cbk0.google.com/cbk?output=tile&panoid=yerN9BDKmxDjHiavUjrDNQ&zoom=1&x=0&y=0


But with zoom 3 we get way more details, we get this 18, 512x512 images. Sometimes, zoom 5 is available, which gives you 338 images, all 512px in width by 512px in height. That is a lot of detail, but that is also super resourceful. It's probably why this info is not released by Google, it's not some new discovery, but if you were constantly requesting all these images I think it would be a problem.

1 comment:

  1. When I attempt to get the pano id using the call (like your example):

    http://cbk0.google.com/cbk?output=xml&ll=42.3467972,-71.0988861

    all I get is:

    © 2011 GoogleYawkey Way 4Boston, MassachusettsUnited StatesBrookline Avenue / Yawkey WayYawkey Way.

    How do I see the rest of the metadata ?

    thank you!

    ReplyDelete