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
            }
        });
Shai Levy
  • 715
  • 9
  • 25

2 Answers2

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

Mike F
  • 71
  • 4