gpt4 book ai didi

javascript - 谷歌街景 JS 计算航向到人脸标记

转载 作者:行者123 更新时间:2023-11-30 10:00:22 25 4
gpt4 key购买 nike

在此示例中,我如何获取谷歌卡车位置和航向以正确计算街景航向,但我无法执行 panorama.getLocation() 它说未知,但是当我执行 时显示在 Firebug 中console.log(panorama) 并查看对象方法。

function initialize() {
var myPlace = {lat: 33.976827,lng: -118.163889};
var map = new google.maps.Map(document.getElementById('map'), {
center: myPlace,
zoom: 18
});

var panorama = new google.maps.StreetViewPanorama(
document.getElementById('pano'), {
position: myPlace
});

marker = new google.maps.Marker({
position: myPlace,
map: map
});

marker_pano = new google.maps.Marker({
position: myPlace,
map: panorama
});

var heading = google.maps.geometry.spherical.computeHeading(panorama.getPosition(), marker.getPosition());

panorama.setPov({
heading: heading,
pitch: 0
});

map.setStreetView(panorama);

}

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

http://jsfiddle.net/z3b4ubb3/

最佳答案

除了@geocodezip 解决方案之外,还有另一种方法可以实现您想要的:

var panorama, myPlace;

function initialize() {

myPlace = {
lat: 33.976827,
lng: -118.163889
};

var map = new google.maps.Map(document.getElementById('map'), {
center: myPlace,
zoom: 18
});

panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
position: myPlace
});

var marker = new google.maps.Marker({
position: myPlace,
map: map
});

map.setStreetView(panorama);

var sv = new google.maps.StreetViewService();

sv.getPanorama({
location: myPlace,
radius: 50
}, processSVData);
}

function processSVData(data, status) {

if (status === google.maps.StreetViewStatus.OK) {

var marker_pano = new google.maps.Marker({
position: myPlace,
map: panorama
});

var heading = google.maps.geometry.spherical.computeHeading(data.location.latLng, marker_pano.getPosition());

panorama.setPov({
heading: heading,
pitch: 0
});
}
}

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

JSFiddle demo

关于javascript - 谷歌街景 JS 计算航向到人脸标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32064302/

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