google-maps - 用于切换到街景的信息框按钮

标签 google-maps google-maps-api-3 google-street-view

我的信息框中有一个按钮。我想要那个按钮切换到街景。该按钮被触发并切换到街景 View ,但是下面的代码将街景 View 视为与我的谷歌地图完全独立的实体,这意味着我无法缩小回 map View ,并且街景 View 级别上没有可见的标记:

        var fenway = new google.maps.LatLng(this.marker[id].position.jb,this.marker[id].position.kb);

    var panoramaOptions = {
        position: fenway,
        pov: {
            heading: 34,
            pitch: 10
        }
    };

    var panorama = new google.maps.StreetViewPanorama(document.getElementById("map-canvas"), panoramaOptions);
    this.gmap.setStreetView(panorama);

如何修改它以便在当前 map 内触发街景而不是创建一个完全独立的实例?

最佳答案

这对我有用:

    var streetViewMaxDistance = 100;          

    var point = new google.maps.LatLng(this.marker[id].position.jb,this.marker[id].position.kb);
    var streetViewService = new google.maps.StreetViewService();
    var panorama = this.gmap.getStreetView();

    streetViewService.getPanoramaByLocation(point, streetViewMaxDistance, function (streetViewPanoramaData, status) {

        if(status === google.maps.StreetViewStatus.OK){

            var oldPoint = point;
            point = streetViewPanoramaData.location.latLng;

            var heading = google.maps.geometry.spherical.computeHeading(point,oldPoint);            

            panorama.setPosition(point);
            panorama.setPov({
                heading: heading,
                zoom: 1,
                pitch: 0
            });
            panorama.setVisible(true);

        }else{
            // no street view available in this range, or some error occurred
            console.log("Sorry! Street View is not available.");
        }
    });

关于google-maps - 用于切换到街景的信息框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16210571/

相关文章:

android - 我可以在中国使用 Google Maps API吗

android - 根据 LatLngBounds 的 GoogleMap moveCamera 或 animateCamera 不准确

javascript - 谷歌地图连接标记

javascript - 嵌入的 Google map 未显示

angular - 如何在@angular/google-maps infoWindow 中显示动态内容

java - 在 Primefaces 中使用谷歌地图库自动完成地址

javascript - 等待 AngularJS 1 中动态加载的外部脚本

javascript - 如何嵌入街景图像,使其显示街道(而不是建筑物内部)的 View ?

google-maps - 获取 Google StreetView API 的 POV

javascript - 谷歌街景缩放到 Fov