我正在尝试捕捉当谷歌地图上的街景小人图标被丢弃并发送全景位置并缩放到服务器。下面的代码用于监听visible_changed事件。但thePanorama.getZoom()和getPosition()返回undefined。
thePanorama = map.getStreetView();
streetviewChangeListener = google.maps.event.addListener(thePanorama, 'visible_changed', function() {
console.log('visible_changed ');
console.log('streetview panorama position: ' + thePanorama.getPosition() + ' zoom: ' + thePanorama.getZoom());
emitStreetViewEvents({position: thePanorama.getPosition(), zoom: thePanorama.getZoom()});
});
帮助?
答案 0 :(得分:1)
不幸的是,我有一个模拟问题,计算标记全景位置之间的距离以隐藏和显示标记。
我的结论是,使用 visible_changed ,您将获得更改前的位置。
为了实现这一点,我必须为 position_changes 添加一个额外的监听器。 在我的代码中,我需要各种标记,一种链接到全景,一种链接到外部网站,两者都可以在地图模式下看到。在全景模式下,全景标记被隐藏。通过与全景位置的距离来检查网站标记,并且仅显示特定距离内的标记。
google.maps.event.addListener(panorama, 'visible_changed', function() {
if (panorama.getVisible()) {
hideMarkers();
checkZelfstudies();
} else {
showMarkers();
showZelfstudies();
}
});
google.maps.event.addListener(panorama, 'position_changed', function() {
checkZelfstudies();
});
https://developers.google.com/maps/documentation/javascript/streetview?hl=nl#StreetViewEvents
希望这可以帮助您解决问题。它适用于我的代码。
答案 1 :(得分:0)
我只是编码一些东西来更新位置和缩放当pegman在谷歌地图版本3中被删除时,所以,使用你的变量并添加其他一些行,也许它会帮助你:
var marker;
var latlng;
var map;
var panorama;
function initialize(position) {
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
thePanorama.setStreetView(panorama);
google.maps.event.addListener(panorama, 'position_changed', function() {
marker.setMap(null);
marker = new google.maps.Marker({
position: panorama.getPosition(),
map: map,
draggable: false
});
map.setCenter(marker.getPosition());
console.log(marker.position.lat());
console.log(marker.position.lng());
});
google.maps.event.addListener(map, 'zoom_changed', function() {
console.log('zoom_changed');
console.log(thePanorama.getZoom());
});
google.maps.event.addListener(panorama, 'pano_changed', function() {
console.log(panorama.getPano());
});
google.maps.event.addListener(panorama, 'pov_changed', function() {
console.log(panorama.getPov().heading % 360);
console.log(panorama.getPov().pitch);
});
}
我希望它适合你,问候。