本文介绍了从我的应用程序在特定位置打开StreetView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的Android应用中以全景模式打开Goog​​le StreetView.

I'm trying to open the Google StreetView on Panorama mode from my Android app.

我真的想打开Goog​​le StreetView而不是Google Maps,因为我想将它与使用VR Glass的Virtual Reality应用程序一起使用,该应用程序使用立体视图和全景模式.我想要的全景模式是这样的: https://youtu.be/3mQKGEnWxIw

I really wanna open the Google StreetView and not Google Maps, because I wanna use it with a Virtual Reality application that uses a VR Glass, that uses stereo view and panorama mode. The panorama mode that I wanna is like that: https://youtu.be/3mQKGEnWxIw

以下代码打开StreetView应用程序:

The following code opens the StreetView app:

PackageManager pm = this.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.google.android.street");
startActivity(intent);

但是它将在默认屏幕上打开.

But it opens on the default screen.

我发现了如何打开街景的全景活动.首先,我列出了应用程序中可用的活动:

I discovered how to open the panorama Activity of the Street View. First I listed the available Activities from the application:

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);
    }

}

然后,我使用了活动com.google.vr.app.StreetViewApp.StreetViewApp.我可以使用以下代码直接启动StreetView Panorama Activity:

Then I used the Activity com.google.vr.app.StreetViewApp.StreetViewApp. I can launch StreetView Panorama Activity directly using this code:

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);
}

但是我仍然不知道如何将位置参数传递给StreetView.我该怎么办?

But I still don't know how to pass the locations parameters to StreetView. How can I do that?

我已经使用URI进行过测试:

I have tested using 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:

And using 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 App?

But no success. Does anyone know how to pass the location parameters to StreetView App on Panorama mode?

我发现,如果我使用突出显示街景视图"链接或推荐位置,则可以通过传递URI Intent在全景"模式下打开街景视图.我测试了以下链接:

I discovered that if I use a Street View Highlighted link, or a featured location, it is possible to open Street View on Panorama mode, passing the URI Intent. I tested the following links:

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/

More can be found here:https://www.google.com/streetview/

但是仍然不知道如何传递通用位置.

But still don't know how to pass a generic location.

推荐答案

以下是通过传递的坐标打开Goog​​le Street View的方法:

Here's how you can open Google Street View with your passed coordinates:

(我刚刚对其进行了测试,它可以按预期工作)

(I just tested it and it works as expected)

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覆盖了Uri:

You were close! the mistake you made was you overriding the Uri with an incorrect one, on your third code snippet :)

这里有更多详细信息: https://developers.google.com/maps/documentation/urls/android-intents

Here are more details: https://developers.google.com/maps/documentation/urls/android-intents

这篇关于从我的应用程序在特定位置打开StreetView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 22:55