Skip to content

Generating Google Maps markers From Database of GPS in one C

Sopheak Lim

Asked Sep 21, 2015, 2:07 AM EDT1 answer
Share
LinkedInX

Dear all,

I am trying to populate Google Maps V3 with Multiple Markers from SQL Server 2012 Database table.

i am saving the latitude longitude in one column called GPS in this format 11.5642078,104.905664

my problem is the markers is show only one record do not appear all Marker in the maps. Mean that if in table have 20 record it will show 20 marker in maps, But now it can show only one marker in maps.

Please help me.
Thanks in advance
 
I have table tblGPS in SQL Server
 
 NoComName  GPS Introduction
 1 
Capitol Guest house & Restaurant
 11.5643076,104.9055242 Gust House
 2 Sophal Thavy Guest house 11.5526978,104.8258317 House
 
 HTML Code: 
 
 
,
 
C# code: 
 
C#
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KoreanTeam.CMaps
{
    public partial class MapViews : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

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


            }
        }

        private DataTable GetData(string query)
        {
            string conString = ConfigurationManager.ConnectionStrings["Con"].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())
                    {
                        sda.Fill(dt);
                        return dt;

                    }
                }
            }
        }
    }
}

Result Here:  
 
Best regard,
 
Sopheak Lim 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Rashmiranjan Dalabehera
    0
    Hi,
     
    Please declare "infoWindow" and "marker"  as global variable.Like
     
    var  infoWindow=null;
    var marker=null;
     
    then,inside method create the intsance of both
     
     infoWindow=new new google.maps.InfoWindow();
     
    marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: data.ComName
    });
    0