使用computeHeading方法的Google Streetview POV标题

时间:2014-07-07 16:56:48

标签: google-maps google-street-view

我正在尝试使用正确的POV标题加载Google街景。

以下是我要复制的代码: https://stackoverflow.com/a/8381895/1093827

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Directly accessing Street View data</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>

var $this = $(this),
  _lat = $this.data(43.6771085),
  _lng = $this.data(-79.2759397),
  streetViewMaxDistance = 100;          

var point = new google.maps.LatLng(_lat,_lng);
var streetViewService = new google.maps.StreetViewService();
var panorama = spaces.map.map.getStreetView();

function initialize() {


// We get the map's default panorama and set up some defaults.
    // Note that we don't yet set it visible.


//panorama = spaces.map.map.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{
      $this.text("Sorry! Street View is not available.");
        // no street view available in this range, or some error occurred
    }
});
 }

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas" style="width: 100%; height: 100%;float:left"></div>
  </body>
</html>

我的代码有明显错误吗?我似乎无法正确加载页面。非常感谢您对此的帮助。

0 个答案:

没有答案