You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google API程序化上传全景照片至任意坐标?

解决方案:用Street View Publish API程序化上传Photosphere到任意坐标

可以直接通过Google Street View Publish API实现你的需求——无需处理切片,支持将符合规格的Photosphere JPEG上传到任意经纬度坐标,完美替代停服的Android Street View app。

关键步骤

1. 前期准备

  • 启用API:在Google Cloud控制台开启Street View Publish API,并创建OAuth 2.0凭据(用于用户身份认证,上传需要关联谷歌账号)。
  • 验证照片规格:确认你的Photosphere JPEG满足要求:
    • 宽高比为2:1(全景标准)
    • 包含正确的XMP元数据(安卓拍摄的Photosphere默认自带,可通过exiftool -XMP:ProjectionType your_photo.jpg验证,结果应为equirectangular)
    • 分辨率符合谷歌要求(最低7168x3584,你的现有文件应该已达标)

2. 批量上传代码示例(Python)

以下是简化的上传脚本,支持批量处理照片:

from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
import os

# 加载OAuth凭据(从Google Cloud下载的credentials.json文件)
creds = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/streetviewpublish'])
service = build('streetviewpublish', 'v1', credentials=creds)

# 批量上传指定目录下的Photosphere
photo_dir = '/path/to/your/photospheres'
for filename in os.listdir(photo_dir):
    if filename.endswith('.jpg') or filename.endswith('.jpeg'):
        file_path = os.path.join(photo_dir, filename)
        
        # 从文件名或Exif读取坐标(示例为手动替换,实际可自动化获取)
        latitude = 35.6762  # 替换为照片的纬度
        longitude = 139.6503  # 替换为照片的经度
        capture_timestamp = 1690000000  # 替换为拍摄时间戳
        
        # 构建Photo对象
        photo = {
            'pose': {'latLngPair': {'latitude': latitude, 'longitude': longitude}},
            'captureTime': {'seconds': capture_timestamp}
        }
        
        # 执行上传
        media = MediaFileUpload(file_path, mimetype='image/jpeg', resumable=True)
        request = service.photos().create(body=photo, media_body=media)
        
        response = None
        while response is None:
            status, response = request.next_chunk()
            if status:
                print(f"上传 {filename}: {int(status.progress()*100)}%")
        print(f"{filename} 上传完成,ID: {response['photoId']['id']}")

3. 注意事项

  • 配额限制:免费额度足够个人批量上传,若上传量极大,需在Google Cloud控制台查看并调整配额。
  • 内容合规:确保照片不包含隐私信息、敏感地点,符合谷歌街景内容政策,否则上传的照片可能被移除。
  • 坐标准确性:可通过读取照片的Exif GPS信息自动填充坐标,避免手动输入错误。

内容的提问来源于stack exchange,提问作者Hugh W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 01:13:00