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

如何利用ARCore Geospatial API获取摄像头指向目标的lat/long及StreetView位置?

使用ARCore Geospatial API获取摄像头指向目标的位置

核心思路

通过设备的地理姿态数据结合射线检测,将摄像头正前方的射线转换为地球坐标系下的坐标,再结合Street View数据获取地址信息。

步骤1:计算摄像头正前方目标的经纬度

  • 获取当前设备的GeospatialPose,从中提取设备的经纬度、高度及姿态参数:
    GeospatialPose devicePose = session.getGeospatialPose();
    
  • 创建屏幕中心的射线(代表摄像头正前方方向):
    Ray forwardRay = frame.createRay(0.5f, 0.5f);
    
  • 将射线从设备局部坐标系转换到ECEF(地球中心地球固定)坐标系:
    Pose ecefPose = devicePose.getEcefPose();
    Pose rayOriginEcef = ecefPose.compose(forwardRay.getOrigin());
    Vector3 rayDirectionEcef = ecefPose.rotateVector(forwardRay.getDirection());
    
  • 计算射线与WGS84椭球面的交点(目标位置的ECEF坐标),再转换为经纬度:
    // 实现WGS84椭球交点计算逻辑
    Vector3 targetEcef = calculateEllipsoidIntersection(rayOriginEcef, rayDirectionEcef);
    GeospatialPose targetPose = session.getGeospatialPoseFromEcef(targetEcef.x, targetEcef.y, targetEcef.z);
    
    double targetLatitude = targetPose.getLatitude();
    double targetLongitude = targetPose.getLongitude();
    
    注:calculateEllipsoidIntersection需要基于WGS84椭球参数(长半轴6378137m,扁率1/298.257223563)实现射线与椭球的交点计算。

步骤2:通过Street View获取目标地址

  • 用步骤1得到的目标经纬度,调用ARCore的Street View相关接口获取全景信息:
    StreetViewPanorama panorama = session.getStreetViewPanorama(targetPose);
    if (panorama != null) {
        String address = panorama.getAddress();
        // 处理地址信息
    }
    
  • 若需更详细的地址数据,可结合目标经纬度调用地理编码服务(需确保合规使用)。

关键注意事项

  • 需在户外无遮挡、GPS信号良好的环境下测试,保证Geospatial定位精度。
  • 若目标不在地面,需调整交点计算逻辑,手动指定目标高度或通过平面检测获取目标实际高度。
  • 使用Street View相关功能前,需确认应用已启用ARCore Geospatial API权限,并遵守谷歌服务条款。

内容的提问来源于stack exchange,提问作者Cristian Gruita

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 19:20:53