Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在FormView的Edittemplate中显示Google地图时遇到问题_Javascript_Asp.net_Google Maps_Formview - Fatal编程技术网

Javascript 在FormView的Edittemplate中显示Google地图时遇到问题

Javascript 在FormView的Edittemplate中显示Google地图时遇到问题,javascript,asp.net,google-maps,formview,Javascript,Asp.net,Google Maps,Formview,我正在从数据库中提取地址数据以显示在FormView上。我使用一个带有window.onload函数的Javascript,该函数从我的代码后台(经度和纬度)接收数据。formview位于UpdatePanel中 这对ItemTemplate很有效,但EditTemplate中不会显示相同的映射。我假设它与我使用的(getElementById(“dvMap”)代码有关,而在EditTemplate中找不到该代码 我如何使这段代码更有效地在任一模板中显示地图 Thx window.onload

我正在从数据库中提取地址数据以显示在FormView上。我使用一个带有window.onload函数的Javascript,该函数从我的代码后台(经度和纬度)接收数据。formview位于UpdatePanel中

这对ItemTemplate很有效,但EditTemplate中不会显示相同的映射。我假设它与我使用的(getElementById(“dvMap”)代码有关,而在EditTemplate中找不到该代码

我如何使这段代码更有效地在任一模板中显示地图

Thx


window.onload=函数(){
变量映射选项={
中心:新建google.maps.LatLng(标记[0].lat,标记[0].lng),
缩放:17,
mapTypeId:google.maps.mapTypeId.SATELLITE
};
var infoWindow=new google.maps.infoWindow({maxWidth:200});
var map=new google.maps.map(document.getElementById(“dvMap”)、mapOptions);
对于(i=0;i
我最终使用了位于 [1] 当前位置我所有的痛苦都消失了

<script type="text/javascript">

     window.onload = function () {
         var mapOptions = {
             center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
             zoom: 17,
             mapTypeId: google.maps.MapTypeId.SATELLITE
         };
         var infoWindow = new google.maps.InfoWindow({ maxWidth: 200 });
         var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
         for (i = 0; i < markers.length; i++) {
             var data = markers[i]
             var myLatlng = new google.maps.LatLng(data.lat, data.lng);
             var marker = new google.maps.Marker({
                 position: myLatlng,
                 map: map,
                 title: data.title
             });
             (function (marker, data) {
                 google.maps.event.addListener(marker, "click", function (e) {
                     infoWindow.setContent(data.description);
                     infoWindow.open(map, marker);
                 });
             })(marker, data);
         }
     }
 </script>

HTML
<asp:Literal runat="server" ID="jsLiteral"></asp:Literal>
<div id="dvMap" style="width: 100%; height: 400px">  </div>

CodeBehind vb.Net
        Dim jsLiteral As Literal = DirectCast(formviewRecord.FindControl("jsLiteral"), Literal)
    If (_Record.Long IsNot Nothing) And (Not String.IsNullOrWhiteSpace(_Record.Long)) And (_Record.Lat IsNot Nothing) And (Not String.IsNullOrWhiteSpace(_Record.Lat)) Then
        Dim js As New StringBuilder
        js.Append("<script type='text/javascript'>")
        js.Append("var markers = [")
        js.Append(" {")
        js.Append("title: 'test',")
        js.Append("lat:  " + _Record.Lat + ",")
        js.Append("lng:  " + _Record.Long + ",")
        js.Append("description: 'description'")
        js.Append("  }")
        js.Append("];")
        js.Append("</script>")

        jsLiteral.Text = js.ToString

    End If