0
我試圖用asp.net mvc製作一個網站4 & EF6我想從MSSQL表中將值傳遞給javascript。到目前爲止一切工作正常,除非我通過Latitude
& Longitude
值google-map-api
函數,地圖不顯示在我的視圖。我使用Html.HiddenFor
幫手來傳遞來自<span>
的值。這裏是我的代碼,將MSSQL表值傳遞給javascript
控制器
public ActionResult BranchDetails(int BrId)
{
Branch branchDetails = abdb.Branches.Find(BrId);
return View(branchDetails);
}
查看
<script>
function initialize() {
var marker;
var LatTag = document.getElementById("Lat");
var Lat = LatTag.getElementsByTagName("span");
var LngTag = document.getElementById("Lng");
var Lng = LngTag.getElementsByTagName("span");
var mapProp = {
center: new google.maps.LatLng(LatTag, LngTag),
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
marker = new google.maps.Marker({
position: new google.maps.LatLng(Lat, Lng),
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body>
<div class="container well" style="min-width: 100%; padding-right: 5px;">
<div id="googleMap"></div>
<span id="Lat">@Html.HiddenFor(model => model.Latitude)</span>
<span id="Lng">@Html.HiddenFor(model => model.Longitude)</span>
<h4><b>@Html.DisplayFor(model => model.Title)</b></h4>
<p><strong>Address:</strong> @Html.DisplayFor(model => model.Address)</p>
<p><strong>Contact No. :</strong> @Html.DisplayFor(model => model.ContactNo)</p>
<p><strong>Contact Person(s):</strong> @Html.DisplayFor(model => model.ContactPerson)</p>
</div>
</body>
點要注意的是在MSSQL我Longitude
& Latitude
字段varchar
模式設置。我不確定它是否會導致問題,但只是需要通知。我怎麼解決這個問題?糟糕的需要這個幫助。 TNX。