Add The Pins

bingmap2

Now we have the data and the map we need to start  putting it all together. First lets look a xaml to display the map.

<Window x:Class=”StateCaps.MainWindow”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243;
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;
xmlns:m=”clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF”
xmlns:local=”clr-namespace:StateCaps”
mc:Ignorable=”d”
Title=”MainWindow” Height=”450″ Width=”625″>
<Window.Resources>
</Window.Resources>
<Grid>
<m:Map x:Name=”myMap” CredentialsProvider=”YOUR KEY HERE” Mode=”Road” Center=”35.665600,-95.469700″ ZoomLevel=”3″>
</m:Map>
</Grid>
</Window>

This  will give you a very simple map of the us.  To add the pus pin we need write some code in c#. So in the mainwindow.xaml.cs add the following method.

private void GetPush(DataSet Ds)
{
int rcount = Ds.Tables[0].Rows.Count;
for (int i = 0; i < rcount; i++)
{
string strLat = Ds.Tables[0].Rows[i].Field<string>(“Lat”);
string strLong = Ds.Tables[0].Rows[i].Field<string>(“Log”);
string strCap = Ds.Tables[0].Rows[i].Field<string>(“Capital”);
Double results1, results2;
results1 = Convert.ToDouble(strLat);
results2 = Convert.ToDouble(strLong);
//string iconStyle = 16;
Pushpin pushpin1 = new Pushpin();
//pushpin1.Style.Resources = Application.Current.Resources[“pushpin”];
pushpin1.PositionOrigin = PositionOrigin.Center;
//pushpin1.Location = new Location(45, -90);
pushpin1.Content = strCap;
pushpin1.Height = 55;
pushpin1.FontSize = 8;
pushpin1.Background = new SolidColorBrush(Colors.Red);
pushpin1.Foreground = new SolidColorBrush(Colors.Black);
MapLayer.SetPosition(pushpin1, new Location(results1, results2));
myMap.Children.Add(pushpin1);
}

We need to then call the method in Make Dataset() method. (I know there are better ways of doing this bear with me.)

public void MakeDataSet()
{
DataTable table1 = new DataTable(“StateCapitals”);
table1.Columns.Add(“STATE”);
table1.Columns.Add(“Capital”);
table1.Columns.Add(“LAT”);
table1.Columns.Add(“LOG”);
table1.Rows.Add(“Alabama”, “Montgomery”, “32.361538”, “-86.279118”);
table1.Rows.Add(“Alaska”, “Juneau”, “58.301935”, “-134.419740”);
table1.Rows.Add(“Arizona”, “Phoenix”, “33.448457”, “-112.073844”);
table1.Rows.Add(“Arkansas”, “Little Rock”, “34.736009”, “-92.331122”);
table1.Rows.Add(“California”, “Sacramento”, “38.555605”, “-121.468926”);
table1.Rows.Add(“Colorado”, “Denver”, “39.7391667”, “-104.984167”);
table1.Rows.Add(“Connecticut”, “Hartford”, “41.767”, “-72.677”);
table1.Rows.Add(“Delaware”, “Dover”, “39.161921”, “-75.526755”);
table1.Rows.Add(“Florida”, “Tallahassee”, “30.4 …
DataSet set = new DataSet(“StateCapitals”);
set.Tables.Add(table1);
GetPush(set);}

At this point we have meet our goal of making a map.  But it is important to understand the method. First of all awe pushed the data as an object.  Where did we get the data.  In the previous code we created it using:

DataSet set = new DataSet(“StateCapitals”);
set.Tables.Add(table1);

We go into detail in the next post.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s