最近的街景照片到坐标

时间:2015-06-16 14:09:05

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

我正在使用Google Maps V3 API开展概念验证应用程序。我有一个数据库,其中列出了所有城市及其中心点(latlng)格式。当我从数据库中打开一个随机城市时,地图以中心点为中心并切换到街景视图。

问题是:有时会有用户提交的照片,在这种情况下没有“步行”功能。以下是此类照片的示例,该照片也是街景图层的一部分:

enter image description here

有没有办法避免这些用户照片,并且它们与谷歌地图API的立场不同于谷歌司机使用“步行”功能制作的真实照片?我需要一种方法,使用Google汽车的“正确”街景照片跳到下一个最近的点。

另一个问题:有没有办法/算法找到最近的街道观点指向给定的坐标?

以下是当前的代码段:

      var point = new google.maps.LatLng(data[0].lat, data[0].lng);

      var webService = new google.maps.StreetViewService();
      var checkaround = 5000;
      webService.getPanoramaByLocation(point,checkaround ,function(panoData) {
        if(panoData){

             if(panoData.location){

                if(panoData.location.latLng){
                      window.map.setCenter(panoData.location.latLng);
                      window.map.setZoom(14);
                      var panoramaOptions = {
                        position: panoData.location.latLng,
                        pov: {
                          heading: 34,
                          pitch: 10
                        }
                      };
                      var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
                      map.setStreetView(panorama);
                }
            }
        }
      });

我无法在jsfiddle上发布它,因为有一个带数据库的php后端,但是上面的代码和测试点(latlng)=(54.226978,49.568459)你可以重新创建问题,你会看到照片,而不是街景。然而,这个城市和街景视图涵盖了这一点。

2 个答案:

答案 0 :(得分:1)

问题可能是您的来电getPanoramaByLocation()。如果你省略它,它可能会工作,只需这样做:

  var point = new google.maps.LatLng(54.226978, 49.568459);

  window.map.setCenter(point);
  window.map.setZoom(14);
  var panoramaOptions = {
    position: point,
    pov: {
      heading: 34,
      pitch: 10
    }
  };
  var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
  map.setStreetView(panorama);

或者如果你想getPanoramaByLocation(),你应该在回调中拨打setPano(),如下所示:

  var point = new google.maps.LatLng(data[0].lat, data[0].lng);

  var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'));

  var webService = new google.maps.StreetViewService();
  var checkaround = 5000;
  webService.getPanoramaByLocation(point,checkaround ,function(panoData) {
    if(panoData){

         if(panoData.location){

            if(panoData.location.latLng){
                  window.map.setCenter(panoData.location.latLng);
                  window.map.setZoom(14);

                  panorama.setPano(panoDdata.location.pano);
                  panorama.setPov({
                    heading: 34,
                    pitch: 10
                  });
                  panorama.setVisible(true);

                  map.setStreetView(panorama);
            }
        }
    }
  });

答案 1 :(得分:0)

您可以尝试使用Roads API flattenDict方法。

此方法采用沿路线收集的GPS点数,然后返回并将点捕捉到车辆行驶的最可能的道路