多个标记谷歌地图API V3与文字Asp.网络控制

本文关键字:文字 Asp 网络 控制 V3 API 谷歌地图 | 更新日期: 2023-09-27 18:15:05

我使用以下代码添加标记在谷歌地图(API V3),我使用XML文件存储位置

 protected void Page_Load(object sender, EventArgs e)
        {
            string locations = "";
            string lastlat = "", lastlng = "";
            XDocument xmlDoc = XDocument.Load(Server.MapPath("~/App_Data/Map.xml"));
            var query = from st in xmlDoc.Descendants("Position")
                        select st;
            foreach (var p in query)
            {
                lastlat = p.Element("Latitude").Value;
                lastlng = p.Element("Longitude").Value;
                locations += "var marker = new google.maps.Marker({position: new google.maps.LatLng(" 
                    + p.Element("Latitude").Value + "," 
                    + p.Element("Longitude").Value + "),info:'"" 
                    + p.Element("Name").Value + "'",title:'""
                    + p.Element("Name").Value + "'",map: map});marker.setMap(map)";
            }
            Label1.Text = locations;
            js.Text = @"<script type='text/javascript'>function initialize() { var myLatlng = new google.maps.LatLng(" + lastlat + "," + lastlng + "); var myOptions = {zoom: 16, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map'), myOptions);" + locations + "marker.setMap(map);}</script>";
        }

和这个代码

<body onload="initialize()">
    <form id="form1" runat="server">
    <table width="100%" border="1">
        <asp:Literal ID="js" runat="server"></asp:Literal>
        <div id="map" style="width:995px;height:600px;"></div>
    </table>
    </form>
</body>

但是没有在网页中显示地图!!

这给出了两个错误

   Uncaught SyntaxError: Unexpected token var
    Uncaught ReferenceError: initialize is not defined 

多个标记谷歌地图API V3与文字Asp.网络控制

后面少了一个分号
var myOptions = {zoom: 16, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP }