如何在JS文件中引用Google Map标签

我正在使用ASP.Net MVC,我们正在使用外部.JS文件放置所有javascript代码。 我首先将下面的Google Map代码放置在View中,并且在视图页面中显示该地图时效果很好...但是当我发送代码进行代码审查时,代码审查人员要求我在.JS中引用它。文件。我尝试了很多次将其放入.JS文件,但无法在视图中显示它。

好像他们想要js文件 airplanDetail.js 中的google map初始化变量和google map js脚本一样,并且仅在视图页面中具有引用。他们想要干净的代码/查看页面

可以请您帮忙吗?

                            <div class="googleMapAPI">
                            @{
                                var googleAPIKey = ConfigurationSettings.AppSettings["CWU_GoogleAPI_Key"];
                                <script src="https://maps.googleapis.com/maps/api/js?key=@googleAPIKey&callback=initMap" type="text/javascript"></script>
                            }

因此,在ASP.Net MVC视图页面的底部,有一个下面的代码引用了JS文件。

@section Scripts {    
    @Scripts.Render("~/Scripts/Views/Product/airplanDetail.js")
}

airplanDetails.js 文件中,有一个类似于下面的代码

$(function () {    

    Initialize();        
});

function Initialize() {

google.maps.visualRefresh = true;

var propertyLatitude = document.getElementById("latitudId").value;
var propertyLongitude = document.getElementById("longitudId").value;
var propertyLocation = new google.maps.LatLng(propertyLatitude,propertyLongitude);
var mapoptions = {
    zoom: 14,center: propertyLocation,mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"),mapoptions);
var myLatlng = new google.maps.LatLng(propertyLatitude,propertyLongitude);
var marker = new google.maps.Marker({
    position: myLatlng,map: map,title: 'Location found'
});


marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png')

}
fleia 回答:如何在JS文件中引用Google Map标签

尝试将script标签放入该部分,即:

<html>
<head>
@Scripts.Render("~/Scripts/Views/Product/airplanDetail.js")
</head>
<body>
</body>
</html>
本文链接:https://www.f2er.com/3123368.html

大家都在问