全景ID列表(街景)
List of Panorama Id (StreetView)
我需要保留一个方向的全景图 ID 列表。我可以通过 Links 和 StreetViewPanorama
的方法得到它。但是我有这个错误:
variablele "Links" is undefined
我的代码是:
var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),{
position: {lat: 37.869, lng: -122.255},
pov: {
heading: 270,
pitch: 0
},
visible: true
});
..
panorama.setPano('SomePAnoCode45994hf9hf');
var Links = panorama.getLinks();
我做错了什么?
我希望通过链接获得下一张全景图:
Links[0].getPano();
Google Maps Javascript API v3 是基于事件的。您需要等待全景图的 "status_changed" 事件触发,然后 getLinks()
才会 return 结果。
google.maps.event.addListener(panorama, 'status_changed', function() {
var status = panorama.getStatus();
if (status == "OK") {
var Links = panorama.getLinks();
console.log(Links);
} else {
alert("panorama status="+panorama.getStatus());
}
});
代码片段:
var panorama;
function initialize() {
panorama = new google.maps.StreetViewPanorama(
document.getElementById('street-view'), {
position: {
lat: 37.869260,
lng: -122.254811
},
pov: {
heading: 165,
pitch: 0
},
zoom: 1
});
var Links = panorama.getLinks();
console.log(Links);
google.maps.event.addListener(panorama, 'status_changed', function() {
var status = panorama.getStatus();
if (status == "OK") {
var htmlStr = "<b>Links:</b><br>";
var Links = panorama.getLinks();
console.log(Links);
for (var i = 0; i < Links.length; i++) {
htmlStr += Links[i].heading.toFixed(3) + ":" + Links[i].description + "<br>";
}
document.getElementById('links').innerHTML = htmlStr;
} else {
alert("panorama status="+panorama.getStatus());
}
});
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#street-view {
height: 100%;
}
<!--
modified from:
https://developers.google.com/maps/documentation/javascript/examples/streetview-embed
-->
<div id="links"></div>
<div id="street-view"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=initialize"></script>
我需要保留一个方向的全景图 ID 列表。我可以通过 Links 和 StreetViewPanorama
的方法得到它。但是我有这个错误:
variablele "Links" is undefined
我的代码是:
var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),{
position: {lat: 37.869, lng: -122.255},
pov: {
heading: 270,
pitch: 0
},
visible: true
});
..
panorama.setPano('SomePAnoCode45994hf9hf');
var Links = panorama.getLinks();
我做错了什么? 我希望通过链接获得下一张全景图:
Links[0].getPano();
Google Maps Javascript API v3 是基于事件的。您需要等待全景图的 "status_changed" 事件触发,然后 getLinks()
才会 return 结果。
google.maps.event.addListener(panorama, 'status_changed', function() {
var status = panorama.getStatus();
if (status == "OK") {
var Links = panorama.getLinks();
console.log(Links);
} else {
alert("panorama status="+panorama.getStatus());
}
});
代码片段:
var panorama;
function initialize() {
panorama = new google.maps.StreetViewPanorama(
document.getElementById('street-view'), {
position: {
lat: 37.869260,
lng: -122.254811
},
pov: {
heading: 165,
pitch: 0
},
zoom: 1
});
var Links = panorama.getLinks();
console.log(Links);
google.maps.event.addListener(panorama, 'status_changed', function() {
var status = panorama.getStatus();
if (status == "OK") {
var htmlStr = "<b>Links:</b><br>";
var Links = panorama.getLinks();
console.log(Links);
for (var i = 0; i < Links.length; i++) {
htmlStr += Links[i].heading.toFixed(3) + ":" + Links[i].description + "<br>";
}
document.getElementById('links').innerHTML = htmlStr;
} else {
alert("panorama status="+panorama.getStatus());
}
});
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#street-view {
height: 100%;
}
<!--
modified from:
https://developers.google.com/maps/documentation/javascript/examples/streetview-embed
-->
<div id="links"></div>
<div id="street-view"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=initialize"></script>