gpt4 book ai didi

javascript - 最接近坐标的街景照片

转载 作者:行者123 更新时间:2023-11-29 21:46:49 26 4
gpt4 key购买 nike

我正在使用 Google Maps V3 API 开发概念验证应用程序。我有一个数据库,其中包含 (lat,lng) 格式的所有城市及其中心点的列表。当我从数据库中打开一个随机城市时, map 以中心点为中心并切换到街景 View 。

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

enter image description here

有没有办法避免这些用户照片?从 Google Maps API 的 Angular 来看,它们与 Google 司机使用“步行”功能拍摄的真实照片有何不同?我需要一种使用 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 后端,但是有上面的代码和一个测试点 (lat,lng) = ( 54.226978, 49.568459) 你可以重现这个问题,你会看到照片而不是街景。然而,这个城市和这个点都被街景覆盖了。

最佳答案

问题可能是您调用 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);
}
}
}
});

关于javascript - 最接近坐标的街景照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com