android - 在特定位置从我的应用程序打开街景
问题描述
我正在尝试从我的 Android 应用程序以全景模式打开 Google StreetView。
我真的想打开谷歌街景而不是谷歌地图,因为我想将它与使用 VR Glass 的虚拟现实应用程序一起使用,该应用程序使用立体视图和全景模式。我想要的全景模式是这样的:https ://youtu.be/3mQKGEnWxIw
以下代码将打开 StreetView 应用程序:
PackageManager pm = this.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.google.android.street");
startActivity(intent);
但它会在默认屏幕上打开。
编辑1:
我发现了如何打开街景的全景活动。首先,我列出了应用程序中可用的活动:
void listAppActivities(String packagename) {
PackageManager pManager = getPackageManager();
Intent startIntent = new Intent();
startIntent.setPackage(packagename);
List<ResolveInfo> activities = pManager.queryIntentActivities(startIntent, 0);
for (ResolveInfo ri : activities) {
System.out.println("getAppActivities::nome::" + ri.activityInfo.name);
}
}
然后我使用了 Activity com.google.vr.app.StreetViewApp.StreetViewApp。我可以使用以下代码直接启动 StreetView Panorama Activity:
void openStreetView() {
String packagename = "com.google.android.street";
PackageManager pm = this.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(packagename);
intent.setComponent(new ComponentName(packagename, "com.google.vr.app.StreetViewApp.StreetViewApp"));
startActivity(intent);
}
但我仍然不知道如何将位置参数传递给街景。我怎样才能做到这一点?
我已经使用 URI 进行了测试:
Uri gmmIntentUri;
//gmmIntentUri = Uri.parse("geo:"+lat+","+lng); // Test1
gmmIntentUri = Uri.parse("google.streetview:cbll="+lat+","+lng); // Test2
//gmmIntentUri = Uri.parse("http://maps.google.com/maps?ll="+lat+","+lng); // Test3
intent.setData(gmmIntentUri);
并使用 Intent.putExtra:
intent.putExtra("cbll", lat+","+lng);
intent.putExtra("args", "cbll="+lat+","+lng);
intent.putExtra("lat", new Double(lat));
intent.putExtra("long", new Double(lng));
intent.putExtra("lng", new Double(lng));
但没有成功。有谁知道如何在全景模式下将位置参数传递给 StreetView 应用程序?
编辑2:
我发现如果我使用 Street View Highlighted 链接或特色位置,则可以在全景模式下打开 Street View,并传递 URI Intent。我测试了以下链接:
https://www.google.com/streetview/#christmas-island/ethel-beach-2 https://www.google.com/streetview/#russian-landmarks/terskol-1 https://www.google。 com/streetview/#day-of-the-dead-in-mexico/ofrenda-dia-de-muertos-zocalo
更多可以在这里找到: https ://www.google.com/streetview/
但仍然不知道如何传递通用位置。
解决方案
以下是使用传递的坐标打开 Google 街景的方法:
(我刚刚对其进行了测试,它按预期工作)
private void openStreetView (double latitude, double longitude) {
Uri gmmIntentUri = Uri.parse ("google.streetview:cbll=" + latitude + "," + longitude);
Intent mapIntent = new Intent (Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage ("com.google.android.apps.maps");
startActivity (mapIntent);
}
你很亲近!Uri
您犯的错误是您在第三个代码段上用不正确的代码覆盖了:)
以下是更多详细信息:https ://developers.google.com/maps/documentation/urls/android-intents
推荐阅读
- python - Keras 中的自定义损失函数 - 迭代 TensorFlow
- mariadb - 如何在 MySQL DB (Windows 10, XAMPP CP v3.2.4) 中更新/插入 Cyrillic 数据?
- .net - 如何在VB.NET中基于cmd输出的进度条
- r - 如何在 Plotly 折线图 R 的行尾添加箭头
- javascript - 如何在反应中正确更新状态
- ruby - MongoDB 查询是否(字段 A - 字段 B)> N
- excel - 将数据添加到特定范围的列
- android - 依赖库冲突导致警告:为外部包 'android' 生成 id 'android:id/icon'
- flutter - 在颤动中旋转容器动画中的颜色
- scala - ClassCastException:java.lang.Double 无法转换为 org。apache.spark.mllib.linalg.Vector 使用 LabeledPoint 时