英文:
Programmatically upload a StreetView panorama
问题
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 can 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 via a Google API?
英文:
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 can 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 via a Google API?
答案1
得分: 1
以下是代码部分的中文翻译:
这里是使用curl的答案。您仍然可以使用Street View Publish API上传与Google Maps“地点”无关的个别全景照片。根据这里的说明。要使用Google APIs,您首先需要一个API密钥和访问令牌,如该页面顶部所述。将它们存储在$API_KEY
和$ACCESS_TOKEN
中。然后需要进行三个API调用。
首先,告诉Google您要上传新的图像。它会返回一个URL,您应该在该URL上POST图像字节。
$ 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"
}
将UPLOAD_URL
设置为上面返回的URL,然后POST实际的图像文件。成功后会得到一个空响应。
$ curl --request POST --url "$UPLOAD_URL" --upload-file 'C:\path\to\photosphere.jpg' --header 'Authorization: Bearer $ACCESS_TOKEN'
最后,根据API文档需要“上传元数据”,例如纬度/经度和拍摄时间,但我发现如果您发送包含最少的uploadUrl的元数据,Google将从EXIF标签中提取正确的姿势值。但是,仍然需要执行这第三个API调用,以使全景照片公开可见。响应包含有关您上传的照片的大量信息。
$ 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"
}
英文:
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"
}
答案2
得分: 0
是的,根据另一个答案,您仍然可以使用Street View Publish API上传具有任意GPS位置的单个全景照片。
以下是一个在C#中的简单示例,使用Google.Apis.StreetViewPublish.v1
和Google.Protobuf
nuget包。它执行与其他答案相同的三个API调用,但首先基于client_secret.json文件设置凭据。您需要先进行一些操作来创建此文件,但有大量文档可供参考。
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";
// 针对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"
});
// 进行第一个API调用以获取UploadUrl
var uploadUrl = service.Photo.StartUpload(null).Execute().UploadUrl;
// 将图像字节发送到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();
// 现在设置(空)图像元数据,Google将从EXIF标签中读取元数据
var uploadRequest = new Photo
{
UploadReference = new UploadRef { UploadUrl = uploadUrl }
};
var result = service.Photo.Create(uploadRequest).Execute();
// JSON响应包含在Google地图中查找您的全景照片的URL
Console.WriteLine(result);
}
}
}
英文:
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);
}
}
}
答案3
得分: -1
你可以使用Google地图Web上传360度照片到街景,只需将照片上传到Google相册并从Google相册添加图像。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论