2016-08-30 6 views
-1
  1. 私のajax呼び出しは次のようになります。

$(ドキュメント).ready(関数(){ここc#.netを使用してデータベースからlong longを取得する方法

$.ajax({ 
    type: "POST", 
    url: "map.aspx/getCityPopulation2", 
    //data: jsonData, 
    contentType: "application/json; charset=utf-8", 
     data: "{}", 
     dataType: "json", 
     success: function (data) { 

      var points = L.geoJson(data, { 
       pointToLayer: function (feature, latlng) { 
        marker = L.marker(latlng, { icon: ratIcon }) 
        marker.bindPopup(feature.properties.Source + '<br/>'); 
        return marker; 
       } 
      }).addTo(pointsCluster); 

      mymap.addLayer(pointsCluster); 
     } 
     }); 

2.私のコードは、クエリが実行されているところから遅れている。

[WebMethod] 
public static List<cityPopulation2> getCityPopulation2() 
{ 
    List<cityPopulation2> p = new List<cityPopulation2>(); 

    using (NpgsqlConnection con = new NpgsqlConnection("Server=Localhost;Port=5432;User Id=postgres;Password=postgres;Database=post;")) 
    { 
     string myQuery = "select complaintlgeolon,complaintlgeolat from mandapet.pgr_demo_view"; 
     NpgsqlCommand cmd = new NpgsqlCommand(); 
     cmd.CommandText = myQuery; 
     cmd.CommandType = CommandType.Text; 
     cmd.Connection = con; 
     con.Open(); 
     NpgsqlDataReader dr = cmd.ExecuteReader(); 
     if (dr.HasRows) 
     { 
      while (dr.Read()) 
      { 
       cityPopulation2 cpData = new cityPopulation2(); 
       cpData.lat = Convert.ToInt32(dr["complaintlgeolon"]); 
       cpData.lng = Convert.ToInt32(dr["complaintlgeolon"]); 

       p.Add(cpData); 
      } 
     } 
    } 

    return p; 
} 

}

public class cityPopulation2 
    { 
     public int lat { get; set; } 
     public int lng { get; set; } 
     // public string id { get; set; } 
    } 

私が間違っているところを指導してください。私はjの息子とplとしてデータを取得する必要がありますあなたのコメントを1としてOTマーカー

+0

ありますかを確認してくださいJavaScriptSerializer

JavaScriptSerializer ASerializer = new JavaScriptSerializer(); //you can create your own custom converter of cityPopulation2 ASerializer.RegisterConverters(new JavaScriptConverter[] {new cityPopulation2()}); var Json = ASerializer.Serialize(p); return Json; 

を使用できるかどうか –

+0

その文字列 – imtiyaz

+0

そして、ajax呼び出しで 'jsonData'とは何ですか? –

答えて

2

あなたは何json..Youを返すようにすることもlag and longのためのあなたのDBの値がここに `pData1`あるものint

+0

本当ですか?あなたはその質問を読んだことがありますか? –

+0

私のlatlongは倍精度である – imtiyaz

+0

あなたのモデルと変換コードを変更してください。 –

関連する問題