Android StreetView checks if there is any view for a given location

I just play with the new StreetView function for Google Play Services 4.4 for Android ( link ), and I was wondering if there is any method / ability to check if there is any “view” / foto material for any given location. When I load a location that StreetView does not cover with, streetViewPanorama.setPosition(someLatLng); I just get a black screen. Any way to check in advance?

+4
source share
2 answers

A black screen appears when the location is missing. Just check if it has been downloaded or not.

@Override
public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {
    mPanorama.setOnStreetViewPanoramaChangeListener(new StreetViewPanorama.OnStreetViewPanoramaChangeListener() {
        @Override
        public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
            if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
                // location is present
            } else {
                // location not available
            }
        }
    });
+10
source
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {
mPanorama.setOnStreetViewPanoramaChangeListener(new StreetViewPanorama.OnStreetViewPanoramaChangeListener() {
    @Override
    public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
        if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
            // location is present
        } else {
            // location not available
        }
    }
});

, ,

StreetViewPanoramaLocation location = mSvp.getLocation();
if (location != null && location.links != null) {
    mSvp.setPosition(location.links[0].panoId);
}

, location null location.links ( ), , ,

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

Edit

, , , . , , onCreateView, 1- .

Handler h = new Handler();
h.postDelayed(new Runnable(){

    @Override
    public void run() {
        StreetViewPanoramaLocation svpl = mSvp.getLocation();

        if(svpl == null){
            Toast.makeText(getActivity(), "Unable to show Street View at this location", Toast.LENGTH_SHORT).show();
        }
    }

}, 1000);

getLocation() , null. , null,

2:

, , , .

getStreetViewPanoramaAsync(new OnStreetViewPanoramaReadyCallback(){
    @Override
    public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {

    }
})

https://developers.google.com/android/reference/com/google/android/gms/maps/StreetViewPanoramaView.html#getStreetViewPanoramaAsync(com.google.android.gms.maps.OnStreetViewPanoramaReadyCallback)

+9

Source: https://habr.com/ru/post/1541423/


All Articles