How to check is streetview is available on location

本小妞迷上赌 提交于 2019-12-11 03:43:27

问题


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

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/23909623/how-to-check-is-streetview-is-available-on-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!