Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I try to plot data from gridview on map like this

[WebMethod]  
        public static string mapgriddata(string FID,string ObID)  
        {  
            try  
            {  
                string result = "";  
                FID = HttpContext.Current.Session["FID"].ToString();  
                ObID = HttpContext.Current.Session["ObID"].ToString();  
                Entities w = new Entities();  
List(spgetdata_ffid_Result) gt = w.spgetdata_ffid(FFID).ToList();  
                DataTable dt = new DataTable();  
                dt.Columns.Add("No", typeof(string));  
                dt.Columns.Add("Longitude", typeof(float));  
                dt.Columns.Add("Latitude", typeof(float));  
              
               
                foreach (var t in gt)  
                {  
                      
                    dt.Rows.Add(t.No, t.Longitude, t.Latitude); 
t.No = HttpContext.Current.Session["No"].ToString();  
t.Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);  
t.Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);   
                }  
               
                result = DataSetToJSON(dt);  
                return result;  
  
            }  
            catch (Exception)  
            {  
                throw new Exception();  
            }   
        }


What I have tried:

query
<script type="text/javascript">  
        $(function () {  
            var FID = '<%=Session["FID"]%>';  
            var ObID = '<%=Session["ObID"]%>';  
            var No = '<%=Session["No"]%>';  
            var longi = '<%=Session["Longitude"]%>';  
            var latit = '<%=Session["Latitude"]%>';  
            var obj = {};  
            obj.FID = FID;  
            obj.ObID = ObID;  
            obj.No = No;  
            obj.longi = longi;  
            obj.latit = latit;  
            getdata(obj);  
            return falase;  
  
        });  
        function getdata(obj) {  
            $.ajax({  
                type: "POST",  
                url: "home.aspx/mapgriddata",  
                contentType: "application/json;charset=utf-8",  
                data: (data.FFID, data.ObID),  
                datatype: "json",  
                async: true,  
                cache: false,  
                success: function (result) {  
                    window.onload = function () {  
                        alert("map2");  
                        debugger;  
                        var latlng = new google.maps.LatLng(24.0895898, 67.0998546);  
                        debugger;  
                        var mapOptions = {  
                 center: new google.maps.LatLng(markers[0].lat, markers[0].lng),  
                            zoom: 8,  
                            center: latlng,  
                            mapTypeId: google.maps.MapTypeId.ROADMAP  
                        };  
                        debugger;  
                        var infoWindow = new google.maps.InfoWindow();  
                        debugger;  
   var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);  
                        debugger;  
                        for (i = 0; i < obj.length; i++) {  
                            var data = obj[i]  
                            var myLatlng = new google.maps.LatLng(obj.latlng);  
                            var marker = new google.maps.Marker({  
                                position: myLatlng,  
                                map: map,  
                                 
                            });  
                            debugger;  
                            (function (marker, obj) {  
              google.maps.event.addListener(marker, "click", function (e) {  
                                 infoWindow.setContent(obj.FID,obj.No,obj.latit,obj.longi);  
                                    infoWindow.open(map, obj);  
                                });  
                            })(marker, data);  
                        }  
                    }  
                },  
                error: function (error) {  
                    alert(error);  
                }  
            });  
        } 
  
              
          
        
</script>


page load
protected void Page_Load(object sender, EventArgs e)  
      {    mapgriddata(Convert.ToString(Session["FID"]),Convert.ToString(Session["ObID"]));    
          }  
  
      }  


but this show error on console
home.aspx:156 Uncaught ReferenceError: getdata is not defined
Posted
Updated 19-Sep-16 0:27am
v9
Comments
super_user 19-Sep-16 5:14am    
[WebMethod]
public static string mapgriddata(string FID,string ObID)
{
try
{
string result = "";
FID = HttpContext.Current.Session["FID"].ToString();
ObID = HttpContext.Current.Session["ObID"].ToString();
Entities w = new Entities();
List(spgetdata_ffid_Result) gt = w.spgetdata_ffid(FFID).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("NO", typeof(string));
dt.Columns.Add("Longitude", typeof(float));
dt.Columns.Add("Latitude", typeof(float));


foreach (var t in gt)
{

dt.Rows.Add(t.No, t.Longitude, t.Latitude);
}
string No = HttpContext.Current.Session["No"].ToString();
float Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);
float Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);
result = DataSetToJSON(dt);
return result;

}
catch (Exception)
{
throw new Exception();
}
}

Karthik_Mahalingam 19-Sep-16 5:15am    
Object reference not set to an instance of an object.
which line
super_user 19-Sep-16 5:18am    
on these lines @Karthik Bangalore
string No = HttpContext.Current.Session["No"].ToString();
float Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);
float Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);
Karthik_Mahalingam 19-Sep-16 5:23am    
replace this line to string No = Convert.ToString( HttpContext.Current.Session["No"]);
super_user 19-Sep-16 5:44am    
check updated question please @Karthik Bangalore

1 solution

Quote:
Uncaught ReferenceError: getdata is not defined


getdata function is enclosed with jquery, remove it.
 $( function getdata(obj) {  

and remove ) at the end of the function.
 
Share this answer
 
Comments
super_user 19-Sep-16 6:32am    
i already do this correction still no markers is display on google map when i check sources jqyery look like
Karthik_Mahalingam 19-Sep-16 6:33am    
does any error in console window?
super_user 19-Sep-16 6:37am    
means still i did not get values in these lines
t.No = Convert.ToString(HttpContext.Current.Session["No"]);
t.Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);
t.Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);
Karthik_Mahalingam 19-Sep-16 6:37am    
make sure you are setting the session values before accessing them
super_user 19-Sep-16 6:42am    
yes in this line i got the values
dt.Rows.Add(t.No, t.Longitude, t.Latitude);
and then i try to save these values in session and then try to call this session in jquery but i did not get values in these lines
t.No = Convert.ToString(HttpContext.Current.Session["No"]);
t.Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);
t.Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);

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