2016-07-11 37 views
0

我試圖讓我的地理定位應用程序工作,並經過大量的驗證和console.log()函數,一切都應該工作。我的問題是它實際上不工作。我只有一個灰色的背景,而不是我想要的StreetView。我的街景應用程序的灰色背景

下面是代碼:

StreetView: function (latitude, longitude) { 
    $('#streetview').css({'width': $(window).width(), 'height': $(window).height()}); 

    var lookTo = {lat: parseFloat(latitude), lng: parseFloat(longitude)}; 
    var latlong = new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude)); 
    var panoOptions = { 
     position: lookTo, 
     panControl: false, 
     addressControl: false, 
     linksControl: false, 
     zoomControlOptions: false 
    }; 
    // initialize a new panorama API object and point to the element with ID streetview as container 
    var pano = new google.maps.StreetViewPanorama(document.getElementById('streetview'), panoOptions); 
    // initialize a new streetviewService object 
    var service = new google.maps.StreetViewService; 
    // call the "getPanoramaByLocation" function of the Streetview Services to return the closest streetview position for the entered coordinates 
    console.log('Pano Positon :'+ pano.getPosition()); 
    service.getPanoramaByLocation(pano.getPosition(), 50, function (panoData) { 
     // if the function returned a result 
     if (panoData != null) { 
      // the GPS coordinates of the streetview camera position 
      var panoCenter = panoData.location.latLng; 
      console.log('PanoCenter' + panoCenter); 
      // the "computeHeading" function calculates the heading with the two GPS coordinates entered as parameters 
      var heading = google.maps.geometry.spherical.computeHeading(panoCenter, latlong); 
      console.log('Heading : '+ heading); 
      // now we know the heading (camera direction, elevation, zoom, etc) set this as parameters to the panorama object 
      var pov = pano.getPov(); 
      pov.heading = heading; 
      pano.setPov(pov); 
      // set a marker on the location we are looking at, to verify the calculations were correct 
      var marker = new google.maps.Marker({ 
       map: pano, 
       position: lookTo 
      }); 
     } else { 
      // no streetview found 
      console.log('not found'); 
     } 
    }); 

} 

我複製的代碼的一部分,我覺得關於谷歌API和有意見。所以它應該是可讀的。 如果有人有想法...

回答

0

嘗試設置縮放參數。如果這不起作用,請注意,如forum所述,版本3.20,3.21,3.22不再可用。檢查這documentation。如果您的瀏覽器是Internet Explorer,請確保您使用supported version並且不要使用兼容模式。

檢查這些相關的問題:

使用google.maps.StreetViewService.getPanoramaByLocation(),以確定是否有可用於指定位置全景。

希望這有助於!

0

謝謝你的回答。

其實,我發現有什麼問題。我沒有安裝白名單插件。

所以行:<access origin='*' />沒有解釋。 我在通過$ .getScript獲取Google Api腳本後調用了這個函數(StreetView函數)。 由於不接受跨域請求,因此從未調用Ajax調用。