Opening StreetView from my app at a specific locat

2019-02-25 08:19发布

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

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

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.

EDIT 1:

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

}

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

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

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

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

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

EDIT 2:

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

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

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

1条回答
别忘想泡老子
2楼-- · 2019-02-25 09:08

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

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

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

查看更多
登录 后发表回答