Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone,

I am unable to display multiple markers due to this error i.e;
Index and length must refer to a location within the string.
Parameter name: length

Source code:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        string markers = GetMarkers();
        Literal1.Text = @"
     <script type='text/javascript'>
     function initialize() {
 
     var mapOptions = {
     center: new google.maps.LatLng(28.3213, 77.5435),
     zoom: 2,
     mapTypeId: google.maps.MapTypeId.ROADMAP
     };
 
     var myMap = new google.maps.Map(document.getElementById('mapArea'),
     mapOptions);"
        + markers +
        @"}
     </script>";
    }


    protected string GetMarkers()
    {
        string markers = "";
        using (SqlConnection con = new
        SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HostelConnectionString"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("select VillageNm,lattitude,longitude,HostelName,DistrictCd,TalukCd,Hostel_Coordinates from FinYearHostelDetails  left join  Hostelinformation  on FinYearHostelDetails.Hostelcd=Hostelinformation.Hostelcd", con);
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            int i = 0;

            while (reader.Read())
            {
                i++;

                markers +=
                @"var marker" + i.ToString() + @" = new google.maps.Marker({
              position: new google.maps.LatLng(" + ConvertDegree(reader["Lattitude"].ToString()) + ", " +
                ConvertDegree(reader["Longitude"].ToString()) + ")," +
                @"map: myMap,
              title:'" + reader["HostelName"].ToString() + "'});";

       

      


            }
        }
        return markers;
    }

    
    public double ConvertDegree(string  input)
    {

        double sd = 0.0;
        double min = 0.0;
        double sec = 0.0;
        double deg = 0.0;
        string direction = input.Substring(0, 1);
        string sign = "";
        if ((direction.ToUpper() == "S") || (direction.ToUpper() == "W"))
        {
            sign = "-";
        }

        string[] arr = input.Split(new char[] { ' ' });
        min = Convert.ToDouble(arr[2]);
        string[] arr1 = arr[3].Split(new char[] { '.' });
        sec = Convert.ToDouble(arr1[0]);
        deg = Convert.ToDouble(arr[1]);
        min = min / ((double)60);
        sec = sec / ((double)3600);
        sd = deg + min + sec;
        if (!(string.IsNullOrEmpty(sign)))
        {
            sd = sd * (-1);
        }
        sd = Math.Round(sd, 6);
        string sdnew = Convert.ToString(sd);
        string sdnew1 = "";
        sdnew1 = string.Format("{0:0.000000}", sd);

        double manu = Convert.ToDouble(sdnew1.ToString());
        return manu;
        
        
    }


Solution please !
Posted
Updated 1-Mar-15 19:57pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900