scropio gurl

scropio gurl

  • NA
  • 147
  • 99.2k

Show data on map Jquery

Sep 19 2016 5:00 AM
I try to plot data from gridview on map like this
  1. [WebMethod]  
  2.         public static string mapgriddata(string FID,string ObtID)  
  3.         {  
  4.             
  5.             try  
  6.             {  
  7.                 string result = "";  
  8.                 FID = HttpContext.Current.Session["FID"].ToString();  
  9.                 ObID = HttpContext.Current.Session["ObID"].ToString();  
  10.                 Entities w = new Entities();  
  11.                 List<spgetdata_ffid_Result> gt = w.spgetdata_ffid(FFID).ToList();  
  12.   
  13.                 DataTable dt = new DataTable();  
  14.                 dt.Columns.Add("NO", typeof(string));  
  15.                 dt.Columns.Add("Longitude", typeof(float));  
  16.                 dt.Columns.Add("Latitude", typeof(float));  
  17.               
  18.                
  19.                 foreach (var t in gt)  
  20.                 {  
  21.                       
  22.                     dt.Rows.Add(t.No, t.Longitude, t.Latitude);  
  23.                     
  24.                      
  25.                 }  
  26.   
  27.                 string No = HttpContext.Current.Session["No"].ToString();  
  28.                  
  29.                 float Latitude = Convert.ToSingle(HttpContext.Current.Session["Latitude"]);  
  30.                 float Longitude = Convert.ToSingle(HttpContext.Current.Session["Longitude"]);  
  31.   
  32.                   
  33.                 result = DataSetToJSON(dt);  
  34.                 return result;  
  35.   
  36.             }  
  37.             catch (Exception)  
  38.             {  
  39.                 throw new Exception();  
  40.   
  41.   
  42.             }  
  43.   
  44.         }  
jquery
  1. <script type="text/javascript">  
  2.         $(function () {  
  3.             var FID = '<%=Session["FID"]%>';  
  4.             var ObID = '<%=Session["ObID"]%>';  
  5.             var No = '<%=Session["No"]%>';  
  6.            
  7.             var longi = '<%=Session["Longitude"]%>';  
  8.             var latit = '<%=Session["Latitude"]%>';  
  9.   
  10.   
  11.             var obj = {};  
  12.             obj.FID = FID;  
  13.             obj.ObID = ObID;  
  14.             obj.No = No;  
  15.             obj.longi = longi;  
  16.             obj.latit = latit;  
  17.   
  18.             getdata(obj);  
  19.             return falase;  
  20.   
  21.         });  
  22.         $(function getdata(obj) {  
  23.             $.ajax({  
  24.                 type: "POST",  
  25.                 url: "home.aspx/mapgriddata",  
  26.                 contentType: "application/json;charset=utf-8",  
  27.                 data: (data.FFID, data.ObID),  
  28.                 datatype: "json",  
  29.                 async: true,  
  30.                 cache: false,  
  31.   
  32.                 success: function (result) {  
  33.                     window.onload = function () {  
  34.                         alert("map2");  
  35.                         debugger;  
  36.                         var latlng = new google.maps.LatLng(24.0895898, 67.0998546);  
  37.                         debugger;  
  38.                         var mapOptions = {  
  39.   
  40.                             center: new google.maps.LatLng(markers[0].lat, markers[0].lng),  
  41.                             zoom: 8,  
  42.                             center: latlng,  
  43.                             mapTypeId: google.maps.MapTypeId.ROADMAP  
  44.                         };  
  45.                         debugger;  
  46.                         var infoWindow = new google.maps.InfoWindow();  
  47.                         debugger;  
  48.                         var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);  
  49.                         debugger;  
  50.                         for (i = 0; i < obj.length; i++) {  
  51.                             var data = obj[i]  
  52.                             var myLatlng = new google.maps.LatLng(obj.latlng);  
  53.                             var marker = new google.maps.Marker({  
  54.                                 position: myLatlng,  
  55.                                 map: map,  
  56.                                  
  57.                             });  
  58.                             debugger;  
  59.                             (function (marker, obj) {  
  60.                                 google.maps.event.addListener(marker, "click", function (e) {  
  61.                                  infoWindow.setContent(obj.FID,obj.No,obj.latit,obj.longi);  
  62.                                     infoWindow.open(map, obj);  
  63.                                 });  
  64.                             })(marker, data);  
  65.                         }  
  66.                     }  
  67.                 },  
  68.                 error: function (error) {  
  69.                     alert(error);  
  70.                 }  
  71.             });  
  72.         });  
  73.   
  74.               
  75.           
  76.         
  77. </script>  
 page load 
  1. protected void Page_Load(object sender, EventArgs e)  
  2.       {  
  3.         mapgriddata(Convert.ToString(Session["FID"]),Convert.ToString(Session["ObID"]));  
  4.                
  5.             
  6.           }  
  7.   
  8.       }  
 
but this show error
Object reference not set to an instance of an object. 
 

Answers (14)