如何通过Java Intent全屏打开Google Street View?
解决Google街景全屏打开问题
要直接全屏打开Google街景,你需要调整Intent的触发参数,以下是两种可行方案:
方案1:修改URI参数(无需额外依赖)
原URI仅定位到目标坐标,未指定进入全屏的指令。你可以在URI中添加cbp参数,强制跳过预览界面直接进入全屏街景:
String uri = String.format("google.streetview:cbll=%f,%f&cbp=1,99.9,,0,1.0", latitude, longitude); Intent streetViewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); streetViewIntent.setPackage("com.google.android.apps.maps"); if (streetViewIntent.resolveActivity(getReactApplicationContext().getPackageManager()) != null) { streetViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getReactApplicationContext().startActivity(streetViewIntent); }
参数说明
cbp参数格式为cbp=<pitch>,<yaw>,<zoom>,<bearing>,<tilt>,其中:
- 最后一个参数设为
1.0会触发全屏模式 - 前序参数可按需调整视角、朝向,示例值为通用全屏适配参数
方案2:使用Google Maps SDK专用Intent(更灵活)
如果URI参数方案不生效,可以依赖Google Play Services库,使用官方提供的街景专用Intent:
1. 添加依赖
在项目build.gradle中引入Maps SDK依赖:
implementation 'com.google.android.gms:play-services-maps:18.2.0'
2. 实现代码
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.StreetViewPanoramaOptions; import com.google.android.gms.maps.StreetViewPanoramaIntent; LatLng targetLocation = new LatLng(latitude, longitude); StreetViewPanoramaOptions options = new StreetViewPanoramaOptions() .position(targetLocation) .setPanningGesturesEnabled(true) .setZoomGesturesEnabled(true); Intent streetViewIntent = StreetViewPanoramaIntent.createStreetViewPanoramaIntent( getReactApplicationContext(), options); streetViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getReactApplicationContext().startActivity(streetViewIntent);
该方案能精准控制街景启动状态,确保直接进入全屏模式。
内容的提问来源于stack exchange,提问作者Pedro Furquim
相关产品推荐
相关产品推荐

