在地图问题上显示数据库中的位置

时间:2015-10-21 10:22:22

标签: javascript c# asp.net google-maps-api-3

您好我从数据库获取客户位置以在谷歌地图中显示它 代码工作正常但问题是如果最后一个客户位置列等于null,则地图不会加载并且剂量显示任何引脚



<script type="text/javascript">
    var markerArray = [];
    window.onload = function () {

        var t = self.setTimeout(function () {

            var size = $('.LocationLabel').length;
            for (i = 0; i < size; i++) {
                var markers = { locationLatitude: "", locationLongitude: "", Cust_Name: "", Address: "" };
                var Location = $('.LocationLabel').eq(i).text();
                var CustName = $('.Cust_NameLabel').eq(i).text();
                var Address = $('.AddressLabel').eq(i).text();
                markers.locationLatitude = Location.split(',')[0];
                markers.locationLongitude = Location.split(',')[1];
                markers.Cust_Name = CustName;
                markers.Address = Address;
                markerArray.push(markers);

            }

            var mapOptions = {
                center: new google.maps.LatLng(markers.locationLatitude, markers.locationLongitude),
                zoom: 12,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            for (i = 0; i < markerArray.length; i++) {
                var data = markerArray[i]
                var myLatlng = new google.maps.LatLng(data.locationLatitude, data.locationLongitude);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title: data.Cust_Name
                });
                (function (marker, data) {
                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.setContent(data.Address);
                        infoWindow.open(map, marker);
                    });
                })(marker, data);
            }
        }, 2000);
    }
</script>
&#13;
&#13;
&#13;

  <asp:Label ID="lbl_Location" CssClass="LocationLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Location")%>' />
            <asp:Label ID="lbl_CustName" CssClass="Cust_NameLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Cust_Name")%>' />
    <asp:Label ID="lbl_Address" CssClass="AddressLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Address")%>' />

markers data-source

if (!this.IsPostBack)
{
DataTable dt = this.GetData("select * from Customer");
rptMarkers.DataSource = dt;
rptMarkers.DataBind();
}

0 个答案:

没有答案
相关问题