2016-08-30 1 views
-1
  1. bekommen Mein Ajax Anruf sieht so aus.

$ (document) .ready (function() {Wie lat lange aus der Datenbank mit C# .net

$.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. Hier ist mein Code hinter, von wo Abfrage ausgeführt wird.

[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; } 
    } 

3.Bitte geben Sie mir eine Anleitung, wo ich falsch liege, ich muss Daten wie j Sohn und pl abholen ot Marker

+0

was 'pData1' hier benutzen kann? –

+0

es ist nur eine Zeichenfolge – imtiyaz

+0

Und was ist 'JsonData' in der Ajax-Aufruf? –

Antwort

2

Wie pro Ihre Kommentare, wenn Sie was json..You zurückzukehren 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; 

Auch stellen Sie sicher, dass Ihre DB-Werte für lag and long sind int

+0

Sind Sie sicher? Hast du die Frage gelesen? –

+0

Meine Latlong sind in doppelter Genauigkeit – imtiyaz

+0

dann ändern Sie Ihr Modell und auch die Konvertierung Code .. –

Verwandte Themen