How to check is streetview is available on location
Asked Answered
S

2

2

I'm using the the Google Maps Android SDK and I'm trying to find out if a StreetView panorama is available is a certain location.

To describe the feature: "If a user click on a map marker and a the location has a panorama then show the panoram, otherwise just zoom the map to the marker location)

I'd rather not create a SupportStreetViewPanoramaFragment if the location doesn't have a panorama. Even if I create it I think the only possible way would be to call setOnStreetViewPanoramaChangeListener and then call setPosition and check the panorama id on the listener... For some reason the listener wasn't called but I didn't try to fix it yet because its feels too cumbersome anyway.

Any elegant solution here ?

I also hope (insist) to avoid calling JavaScript API v3 following this link: https://developers.google.com/maps/documentation/javascript/reference#StreetViewService

var latLng = new google.maps.LatLng(lat, lon);
        streetViewService.getPanoramaByLocation(latLng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
            if (status === google.maps.StreetViewStatus.OK) {
                //ok
            } else {
                //no ok
            }
        });
Shudder answered 28/5, 2014 at 10:51 Comment(4)
I want to check this also. I m trying your above code. I m getting streetViewService cannot be resolved. how to make object of streetViewService. please helpBohner
Make sure you are using the latest Google Play ServicesShudder
yes Its the latest oneBohner
possible duplicate of How to check if position if valid in StreetView in AndroidSadowski
E
0

Simple and Easy

@Override
        public void onStreetViewPanoramaReady(final StreetViewPanorama streetViewPanorama) {
            streetView = streetViewPanorama;
            streetViewPanorama.setOnStreetViewPanoramaChangeListener(new StreetViewPanorama.OnStreetViewPanoramaChangeListener() {
                @Override
                public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
                    if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
                        streetView = streetViewPanorama;
                        streetViewPanorama.setPosition(new LatLng(36.0579667, -112.1430996));
                        StreetViewPanoramaCamera camera = new StreetViewPanoramaCamera.Builder()
                                .bearing(180)
                                .build();
                        streetViewPanorama.animateTo(camera, 100);
                    } else {
                        Toast.makeText(StreetView_Panorama.this, "location not available", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
Evenfall answered 8/11, 2018 at 6:59 Comment(1)
this is crashing the appSmithereens
W
0

You can use street view metadata. If it returns a pano_id for your marker's location you should be good. Using it needs an API key but it uses no credits. StreetView panorama, on the other hand, got super expensive to use when Google changed their cloud pricing earlier this year. So don't even instantiate one unless you are definitely going to use it.

https://developers.google.com/maps/documentation/streetview/metadata

Weylin answered 23/11, 2018 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.