2013-04-25 62 views
2

我有一个信息框内的按钮。我想要那个按钮切换到街景。该按钮被触发并切换到街景,但我的代码将街景视为完全分离的实体,以我的谷歌地图,这意味着我无法缩小到地图视图,并且在街景视图上没有可见的标记:InfoBox按钮切换到街景

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

我该如何修改它,以便在当前地图内触发街景而不是创建完全分离的实例?

回答

3

这为我工作:

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."); 
     } 
    }); 
1

希望这也可能是有用的。与我现有的地图整合这其中:

map是我的谷歌地图实例化类map = new google.maps.Map(el,mapOptions)

pointer是我的实例化的标志:

pointer = new google.maps.Marker({ 
     position: latLng, 
     map: map 
    }); 

而且的latLng是:latLng = new google.maps.LatLng(lat, lng)

我需要的要做的是在下面的代码中添加下面的代码,它监听我的标记点击,当它被点击时,它将街景视图设置为可见。

var panorama = map.getStreetView(); 
    panorama.setPosition(latLng); 
    panorama.setPov({ 
     heading: 45, 
     pitch:-10} 
    ); 

    google.maps.event.addListener(pointer, 'click', function() { 
     panorama.setVisible(true); 
    }); 
0

为setStreetView方法参数使用空将结合嵌入式街道视图当前地图(配有一个X关闭街道视图,并返回到图)。

this.gmap.setStreetView(); 

来源: https://developers.google.com/maps/documentation/javascript/reference?csw=1#Map

绑定的StreetViewPanorama的地图。此全景覆盖默认的StreetViewPanorama,允许地图绑定到地图外部的外部全景。将全景图设置为空可将默认嵌入式全景图返回到地图。

编辑:如果您有多个信息窗口,你可能需要使用这样的功能,以便与标记的位置来更新streeview:

function streetview(location) { 

    location = location.replace('(', '').replace(')', ''); 
    var lat = location.split(',')[0]; 
    var lng = location.split(',')[1]; 
    var latlng = new google.maps.LatLng(lat, lng); 
    this.gmap.setStreetView(); 
    this.gmap.getStreetView().setPosition(latlng); 
}