Programmatically upload a StreetView panorama

541 Views Asked by At

I have many 360 degree panoramas from my Android phone camera, taken in remote parts of the world. I use existing photospheres on Google Maps to plan my travels, and upload my pictures to help others do the same. Until now I used the Android Street View app to upload panoramas but the app was discontinued in March 2023.

Google suggest Street View Studio as a replacement but that only allows video uploads. You can also upload photos through the Google Maps app, but these have to be associated to an existing 'place' so they are useless for documenting remote roads, mountains etc.

Google lets you make a 'custom street view' but that looks massively complicated. I already have the self-contained 360 degree photo files ready in the required resolution and aspect ratio, I don't want to be messing around at different zoom levels serving individual tiles I don't have.

Is there a way to continue uploading photosphere JPEGs to arbitrary coordinates via a Google API?

4

There are 4 best solutions below

0
Hugh W On

Here's an answer using curl. You can still upload individual photo sphere images not linked to a Google Maps 'place' by using the Street View Publish API. Based on the instructions here. To use the Google APIs you first need an API key and access token as described at the top of that page. Store them in $API_KEY and $ACCESS_TOKEN. Then there are three API calls required.

First you tell Google you want to upload a new image. It returns a URL where you should POST the image bytes.

$ curl --request POST --url "https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=$API_KEY" --header "Authorization: Bearer $ACCESS_TOKEN" --header 'Content-Length: 0'

{
  "uploadUrl": "https://streetviewpublish.googleapis.com/media/user/112233445566778899/photo/1234567890"
}

Set UPLOAD_URL to the URL returned above, then POST the actual image file. On success there is an empty response.

$ curl --request POST --url "$UPLOAD_URL" --upload-file 'C:\path\to\photosphere.jpg' --header 'Authorization: Bearer $ACCESS_TOKEN'

Finally you need to 'upload the metadata' like lat/long and capture time according to the API docs, but I found if you send metadata containing just the bare minimum uploadUrl then Google will pick up the correct pose values from the EXIF tags. However you do still need to perform this third API call for the photosphere to be publicly visible. The response contains a bunch of info about your uploaded photo.

$ curl --request POST --url 'https://streetviewpublish.googleapis.com/v1/photo?key=$API_KEY' --header 'Authorization: Bearer $ACCESS_TOKEN' --header 'Content-Type: application/json'  --data '{ "uploadReference": { "uploadUrl": "$UPLOAD_URL" } }'

{
  "photoId": {
    "id": "nsqmdBsi7gBzTxgiKMc8q7NxuQciAbWCBMKf9kaE"
  },
  "pose": {
    "latLngPair": {
      "latitude": 40.1234567,
      "longitude": -120.1122334
    }
  },
  "captureTime": "2022-12-05T06:02:34Z",
  "thumbnailUrl": "https://lh3.googleusercontent.com/p/ogtBgwKGjqqpDuUnuicCcFZZor7apQ7jKCQtnQvG",
  "shareLink": "https://www.google.com/maps/@0,0,0a,90y,90t/data=!3m4!1e1!3m2!cCqKpcfdGC2S5G44BY6R2bfvKV9gmijdJL3gw4kz!2e10",
  "mapsPublishStatus": "PUBLISHED",
  "uploadTime": "2023-05-12T10:58:48Z"
}
0
Hugh W On

Yes as per the other answer you can still use the Street View Publish API to upload individual photosphere images at arbitrary GPS locations.

Here's a crude example in C# which uses the Google.Apis.StreetViewPublish.v1 and Google.Protobuf nuget packages. It makes the same three API calls as the other answer, but first sets up credentials based on a client_secret.json file. You will have to do a bit of messing around first to create this file but there is plenty of documentation out there.

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.StreetViewPublish.v1;
using Google.Apis.StreetViewPublish.v1.Data;

namespace PhotosphereUploader
{
    public static class Example
    {
        public static void Main()
        {
            var secretsPath = @"C:\path\to\client_secret.json";
            var filePath = @"C:\path\to\photosphere.jpg";

            // Authenticate to API
            var secrets = GoogleClientSecrets.FromFile(secretsPath);
            var scopes = new[] { StreetViewPublishService.Scope.Streetviewpublish };
            var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets.Secrets,
                scopes,
                "username",
                CancellationToken.None
            ).Result;
            var service = new StreetViewPublishService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = "Street View upload example"
            });

            // Make the first API call to get UploadUrl
            var uploadUrl = service.Photo.StartUpload(null).Execute().UploadUrl;

            // Send the image bytes to UploadUrl
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + credential.Token.AccessToken);
            var content = new StreamContent(File.Open(filePath, FileMode.Open));
            client.PostAsync(uploadUrl, content).Wait();

            // Now set (empty) image metadata, Google will read metadata from EXIF tags
            var uploadRequest = new Photo
            {
                UploadReference = new UploadRef { UploadUrl = uploadUrl }
            };
            var result = service.Photo.Create(uploadRequest).Execute();
            // JSON response contains URL to find your photosphere in Google Maps
            Console.WriteLine(result);
        }
    }
}
2
Herduin On

You can post 360 Photos on Street View using Google Maps Web, only need to upload the photos to Google Photos and add the image from Google Photos Google Photos Import

0
Dean Z On

You can publish 360 photos to a Place and have them appear on Google Maps at the actual GPS position where the photo was taken or you can publish them to the actual GPS position without a place assigned. This can be done via use of the API in your self developed application or you can use a third-party application. For example, my JPG2GSV tool. Please join the Google group at the link below for access to the tool. It also includes the GEO2JPG tool that can be used to add position metadata to the image file if not available.

JPG2GSV