JavaScript:显示街景地图而不单击“显示”按钮

JavaScript:显示街景地图而不单击“显示”按钮,javascript,google-maps,google-maps-api-3,google-street-view,Javascript,Google Maps,Google Maps Api 3,Google Street View,你好。 我有这个代码,显示了基于纬度和经度的街道地图 按钮点击 <a id="street-view" class="btn btn-outline-primary btn-lg m-1 px-3" href="javascript:;"> <i class="fa fa-map small mr-2"></i>

你好。 我有这个代码,显示了基于纬度和经度的街道地图

按钮点击

<a id="street-view" class="btn btn-outline-primary btn-lg m-1 px-3" href="javascript:;">
                                <i class="fa fa-map small mr-2"></i>
                                View Neighbourhood
                            </a>
显示地图的Js代码

<div id="street"></div>
// Initialize and add street view map
function initStreetView() {
    // The location to load the street view at
    const gpFarms = { lat: 4.836824, lng: 7.0115864 };
    const streetDiv = document.getElementById("street");
    const panorama = new google.maps.StreetViewPanorama(streetDiv, {
        position: gpFarms,
    });
}

我希望在不单击按钮的情况下显示街景地图

您只需删除按钮并在页面加载时执行全景。以下是一个JSFIDLE示例供您参考:

您还可以看到下面的代码:

函数初始化(){
常数gpFarms={
纬度:4.836824,
液化天然气:7.0115864
};
const streetDiv=document.getElementById(“街景”);
const panorama=新建google.maps.StreetViewPanorama(
街分区{
职位:gpFarms
}
);
}
html,
身体{
身高:100%;
保证金:0;
填充:0;
}
#街景{
身高:100%;
}


仍然希望为您的问题使用合适的标签来生成答案,这可能有助于引起注意。
// Initialize and add street view map
function initStreetView() {
    // The location to load the street view at
    const gpFarms = { lat: 4.836824, lng: 7.0115864 };
    const streetDiv = document.getElementById("street");
    const panorama = new google.maps.StreetViewPanorama(streetDiv, {
        position: gpFarms,
    });
}