0

当我从从地址latlng生成的另一个页面获取时latlng,可以显示标记。但是当我从随机拾取latlng生成的页面中获取时latlng,所有标记都没有显示。这是正常的还是我自己的错误?先感谢您。

我将它存储latlng在 sqlserver 中。所以,这些是代码。

这些是后端代码。

 DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(connstr))
        {
            using (SqlCommand cmd = new SqlCommand("select title=city,lat=latitude,lng=longitude,description from googleMap", con))
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                Dictionary<string, object> row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
                return serializer.Serialize(rows);

这些是javascript。

 function initialize() {
    var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
    var mapOptions = {
        center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.ROADMAP
        //  marker:true
    };
    var infoWindow = new google.maps.InfoWindow();
    var map = new google.maps.Map(document.getElementById("map_canvas"), 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) {

            // Attaching a click event to the current marker
            google.maps.event.addListener(marker, "click", function (e) {
                infoWindow.setContent(data.description);
                infoWindow.open(map, marker);
            });
        })(marker, data);
    }
}
google.maps.event.addDomListener(window, 'load', initialize);
4

0 回答 0