Map coordinates from Access db RRS feed

  • Question

  • User2036854097 posted

    Hi everybody, i'm on showing at each customer page, a googlemap with coordinates from access db (Longtitude, Latitude).

    The coordinate data could be either from one  cell (ex: 51.507351, 51.507351), either from 2 cells (lon,lat)

    The point is to grab those data and use them on map in details view.

    Others data i'm grabbing from db are:<asp:Label ID="ElLabel" runat="server" Text='<%# Bind("email") %>'></asp:Label>


    Thanks in advance

    Wednesday, February 22, 2017 11:41 PM

All replies

  • User-271186128 posted

    Hi bluewire,

    Do you mean some cells are saving both longitude and Latitude?

    If so, you could try to split the data in behind code by using split().

    For example :

    In aspx:

       <form id="form1" runat="server">
            <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&key=AIzaSyCasJ_sPlgUab-WAzSpH0DcCUVN25xumBU"></script>
            <script type="text/javascript">
                window.onload = function () {
                    var mapOptions = {
                        center: new google.maps.LatLng(<%= ViewState["Latitude"].ToString()%>,  <%=ViewState["longitude"]%>),
                        zoom: 8,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    var infoWindow = new google.maps.InfoWindow();
                    var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
                        var myLatlng = new google.maps.LatLng(<%=ViewState["Latitude"]%>,  <%=ViewState["longitude"]%> );
                        var marker = new google.maps.Marker({
                            map: map,
                            title: "<%=ViewState["Name"]%> "
                        (function (marker) {
                            google.maps.event.addListener(marker, "click", function (e) {
                                infoWindow.open(map, marker);
            <asp:DetailsView ClientIDMode="Static" ID="DetailsView1" AutoGenerateRows="false" runat="server" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging">
                    <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-CssClass="header" />
                    <asp:BoundField DataField="longitude" HeaderText="longitude" HeaderStyle-CssClass="header" />
                    <asp:BoundField DataField="Latitude" HeaderText="Latitude" HeaderStyle-CssClass="header" />
                    <textarea id="dvMap" rows="50" ></textarea>

    IN behind code:

    protected void Page_Load(object sender, EventArgs e)
                if (!this.IsPostBack)
                    DetailsView1.DataSource = Binddata();
                    DataTable mdt = new DataTable();
                    var mrows = Binddata().Rows[DetailsView1.PageIndex];
                    ViewState["Name"] =mrows["Name"];
                    ViewState["longitude"] = mrows["longitude"];
                    ViewState["Latitude"] = mrows["Latitude"];
                    ViewState["Description"] = mrows["Description"];
            private DataTable Binddata()
                DataTable dt = this.GetData("select * from Locations");
                //DataTable dt = new DataTable();
                //dt.Columns.Add("Name", typeof(string));
                //dt.Columns.Add("longitude", typeof(string));
                //dt.Columns.Add("Latitude", typeof(string));
                //dt.Columns.Add("Description", typeof(string));
                //dt.Rows.Add("Name", "18.523600,72.825800", "", "Desc");
                //dt.Rows.Add("Name1", "73.847800", "18.523600", "Desc2");
                //dt.Rows.Add("Name2", "72.825800", "18.964700", "Desc2");
                DataTable ndt = new DataTable();
                ndt.Columns.Add("Name", typeof(string));
                ndt.Columns.Add("longitude", typeof(string));
                ndt.Columns.Add("Latitude", typeof(string));
                ndt.Columns.Add("Description", typeof(string));
                DataTable dt2 = new DataTable();
                foreach (DataRow row in dt.Rows)
                    var l = row["longitude"].ToString().Split(',');
                    if (l.Count() > 1)
                        ndt.Rows.Add(row["Name"], l[1], l[0], row["Description"]);
                        ndt.Rows.Add(row["Name"], row["longitude"], row["Latitude"], row["Description"]);
                return ndt;
            protected void OnPageIndexChanging(object sender, DetailsViewPageEventArgs e)
                DetailsView1.PageIndex = e.NewPageIndex;
                var mrows = Binddata().Rows[DetailsView1.PageIndex];
                ViewState["Name"] = mrows["Name"];
                ViewState["longitude"] = mrows["longitude"];
                ViewState["Latitude"] = mrows["Latitude"];
                ViewState["Description"] = mrows["Description"];
            private DataTable GetData(string query)
                string conString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString;
                SqlCommand cmd = new SqlCommand(query);
                using (SqlConnection con = new SqlConnection(conString))
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                            return dt;

    You can refer to below link for a tutorial of Google Map in asp.net


    Best Regards,



    Friday, February 24, 2017 9:45 AM