Requesting Google Street View panorama tiles from an origin location

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:48:29

You can download every image and save it in a multidimensional image array. You can then draw each individual tile on to a blank bitmap. This article explains how to download all the tiles.

Here is my c# code that takes a panorama ID and returns a equirectangular 13312x6656 bitmap which can be saved in any image format:

public static Bitmap Panorama(string panoID)
    {
        ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 12;
        Image[,] images = new Image[26, 13];
        Parallel.For(0, 26, x =>
        {
            Parallel.For(0, 13, y =>
            {
                using (WebClient client = new WebClient())
                    images[x, y] = Image.FromStream(new MemoryStream(client.DownloadData(Get.TileURL(panoID, x, y)))); //converts downloaded byte array to image
            });
        });

        Bitmap result = new Bitmap(26 * 512, 13 * 512);
        for (int x = 0; x < 26; x++)
             for (int y = 0; y < 13; y++)
                 using (Graphics g = Graphics.FromImage(result))
                     g.DrawImage(images[x, y], x * 512, y * 512);
        return result;
    }

To get the url you can also use cbk0.google.com. Get.TileURL:

public static string TileURL(string panoID, int x, int y, int zoomLevel = 5)
    {
        return "http://cbk0.google.com/cbk?output=tile&panoid=" + panoID + "&zoom=" + zoomLevel + "&x=" + x + "&y=" + y;
    }

The Parallel.For loops are just to speed things up and can be substituted for normal for loops.

The only issue with this method is that it doesn't work with panos that start with CAoSLEFGMVFpcE. I'm currently trying to find a fix for that and will update this answer if I find a solution.

Note: by doing this you will be breaking Google's terms of service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!