Hi all, I want to display school symbols onto my map without hard-coding it out by typing default coordinates. Instead I would like to retrieve the data from my MS Access database.But now I'm not too sure on how to go about retrieving the data can anyone here give me a tip or two? Thanks!This is the WCF service I added
public List<School> SchoolList()
{
string nwConn = System.Configuration.ConfigurationManager.ConnectionString ["SchoolsConnectionString"].ConnectionString;
var SchoolList = new List<School>();
using (SqlConnection conn = new SqlConnection(nwConn))
{
const string sql = @"SELECT TOP X, Y FROM School";
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlDataReader dr = cmd.ExecuteReader(
CommandBehavior.CloseConnection);
if (dr != null)
while (dr.Read())
{
var School = new School
{
X = dr.GetString(0),
Y = dr.GetString(1),
};
SchoolList.Add(School);
}
return SchoolList;
}
}
}
{
public class School
{
public string SCHOOLNAME { get; set; }
public string ADDRESS { get; set; }
public string DESCRIPTION { get; set; }
public string HYPERLINK { get; set; }
public string X { get; set; }
public string Y { get; set; }
public string ADDRESSPOSTALCODE { get; set; }
public string ICON_NAME { get; set; }
public string Field1 { get; set; }
}
}
XAML
void AddMarkerGraphics()
{
string jsonCoordinateString = "{'Coordinates':[{'X':24537.8865980018,'Y':34796.6839838},{'X':29277.21841791546,'Y':37429.082965709928},{'X':23571.9250473287,'Y':47017.103190500377}]}";
CustomCoordinateList coordinateList = DeserializeJson<CustomCoordinateList>(jsonCoordinateString);
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
for (int i = 0; i < coordinateList.Coordinates.Count; i++)
{
Graphic graphic = new Graphic()
{
Geometry = new MapPoint(coordinateList.Coordinates.X, coordinateList.Coordinates.Y),
Symbol = i > 0 ? RedMarkerSymbol : RedMarkerSymbol
};
graphicsLayer.Graphics.Add(graphic);
}
}