街景 API 不返回街景
Streetview API not returning streetview
我有一个页面应该包含 div 和 google 地图以及 div 和街景。地图工作正常,但是街景根本不显示,它只是一个空 div。但我无法让 JS 抛出错误。
这是我的代码,我可能缺少一些非常明显的代码。
<div id="property_streetview"></div>
<script>
function initialize_StreetMap() {
var streetViewLocation = new google.maps.LatLng(52.39648,-4.071235);
var panoramaOptions = {
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
};
var panorama;
var panorama = new google.maps.StreetViewPanorama(document.getElementById("property_streetview"), panoramaOptions);
}
window.onload = initialize_StreetMap();
</script>
您已经为 LatLng(streetViewLocation
) 定义了一个变量,但是当您想要获取该位置的街景视图时,您必须将此变量用作 position
-属性对于 panoramaOptions
此外,您必须从此行中删除括号:
window.onload = initialize_StreetMap();
...否则该函数将立即执行,而不是onload。
function initialize_StreetMap() {
var streetViewLocation = new google.maps.LatLng(52.39648,-4.071235),
panoramaOptions = {
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
position:streetViewLocation
},
panorama = new google.maps
.StreetViewPanorama(document.getElementById("property_streetview"),
panoramaOptions);
}
window.onload = initialize_StreetMap;
html, body, #property_streetview {
height: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?v=3&.js"></script>
<div id="property_streetview"></div>
我有一个页面应该包含 div 和 google 地图以及 div 和街景。地图工作正常,但是街景根本不显示,它只是一个空 div。但我无法让 JS 抛出错误。
这是我的代码,我可能缺少一些非常明显的代码。
<div id="property_streetview"></div>
<script>
function initialize_StreetMap() {
var streetViewLocation = new google.maps.LatLng(52.39648,-4.071235);
var panoramaOptions = {
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
};
var panorama;
var panorama = new google.maps.StreetViewPanorama(document.getElementById("property_streetview"), panoramaOptions);
}
window.onload = initialize_StreetMap();
</script>
您已经为 LatLng(streetViewLocation
) 定义了一个变量,但是当您想要获取该位置的街景视图时,您必须将此变量用作 position
-属性对于 panoramaOptions
此外,您必须从此行中删除括号:
window.onload = initialize_StreetMap();
...否则该函数将立即执行,而不是onload。
function initialize_StreetMap() {
var streetViewLocation = new google.maps.LatLng(52.39648,-4.071235),
panoramaOptions = {
addressControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
position:streetViewLocation
},
panorama = new google.maps
.StreetViewPanorama(document.getElementById("property_streetview"),
panoramaOptions);
}
window.onload = initialize_StreetMap;
html, body, #property_streetview {
height: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?v=3&.js"></script>
<div id="property_streetview"></div>