Add the Map Data

worldThe next step is to add data. I found my data on the web by doing a simple query for the LAT/LONG of  US state capitals.  I then created a data set based on that information. Here is a sample of the code.

public MainWindow()


public void MakeDataSet()
DataTable table1 = new DataTable(“StateCapitals”);
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.4518”, “-84.27277”);
table1.Rows.Add(“Georgia”, “Atlanta”, “33.76”, “-84.39”);
table1.Rows.Add(“Hawaii”, “Honolulu”, “21.30895”, “-157.826182”);
table1.Rows.Add(“Idaho”, “Boise”, “43.613739”, “-116.237651”);
table1.Rows.Add(“Illinois”, “Springfield”, “39.783250”, “-89.650373”);
table1.Rows.Add(“Indiana”, “Indianapolis”, “39.790942”, “-86.147685”);
table1.Rows.Add(“Iowa”, “Des Moines”, “41.590939”, “-93.620866”);
table1.Rows.Add(“Kansas”, “Topeka”, “39.04”, “-95.69”);
table1.Rows.Add(“Kentucky”, “Frankfort”, “38.197274”, “-84.86311”);
table1.Rows.Add(“Louisiana”, “Baton Rouge”, “30.45809”, “-91.140229”);
table1.Rows.Add(“Maine”, “Augusta”, “44.323535”, “-69.765261”); table1.Rows.Add(“Maryland”, “Annapolis”, “38.972945”, “-76.501157”);
table1.Rows.Add(“Massachusetts”, “Boston”, “42.2352”, “-71.0275”);
table1.Rows.Add(“Michigan”, “Lansing”, “42.7335”, “-84.5467”);
table1.Rows.Add(“Minnesota”, “Saint Paul”, “44.323535”, “-69.765261”);
table1.Rows.Add(“Mississippi”, “Jackson”, “32.320”, “-90.207”);
table1.Rows.Add(“Missouri”, “Jefferson City”, “38.572954”, “-92.189283”);
table1.Rows.Add(“Montana”, “Helana”, “46.595805”, “-112.027031”);
table1.Rows.Add(“Nebraska”, “Lincoln”, “40.809868”, “-96.675345”);
table1.Rows.Add(“Nevada”, “Carson City”, “39.160949”, “-119.753877”);
table1.Rows.Add(“New Hampshire”, “Concord”, “43.220093”, “-71.549127”);
table1.Rows.Add(“New Jersey”, “Trenton”, “40.221741”, “-74.756138”);
table1.Rows.Add(“New Mexico”, “Santa Fe”, “35.667231”, “-105.964575”); table1.Rows.Add(“New York”, “Albany”, “42.659829”, “-73.781339”);
table1.Rows.Add(“North Carolina”, “Raleigh”, “35.771”, “-78.638”);
table1.Rows.Add(“North Dakota”, “Bismarck”, “46.813343”, “-100.779004”);
table1.Rows.Add(“Ohio”, “Columbus”, “39.962245”, “-83.000647”);
table1.Rows.Add(“Oklahoma”, “Oklahoma City”, “35.482309”, “-97.534994”);
table1.Rows.Add(“Oregon”, “Salem”, “44.931109”, “-123.029159”);
table1.Rows.Add(“Pennsylvania”, “Harrisburg”, “40.269789”, “-76.875613”);
table1.Rows.Add(“Rhode Island”, “Providence”, “41.82355”, “-71.422132”);
table1.Rows.Add(“South Carolina”, “Columbia”, “34.000”, “-81.035”);
table1.Rows.Add(“South Dakota”, “Pierre”, “44.367966”, “-100.336378”); table1.Rows.Add(“Tennessee”, “Nashville”, “36.165”, “-86.784”);
table1.Rows.Add(“Texas”, “Austin”, “30.266667”, “-97.75”);
table1.Rows.Add(“Utah”, “Salt Lake City”, “40.7547”, “-111.892622”);
table1.Rows.Add(“Vermont”, “Montpelier”, “44.26639”, “-72.57194”);
table1.Rows.Add(“Virginia”, “Richmond”, “37.54”, “-77.46”);
table1.Rows.Add(“Washington”, “Olympia”, “47.042418”, “-122.893077”);
table1.Rows.Add(“West Virginia”, “Charleston”, “38.349497”, “-81.633294”);
table1.Rows.Add(“Wisconsin”, “Madison”, “43.074722”, “-89.384444”);
table1.Rows.Add(“Wyoming”, “Cheyenne”, “41.145548”, “-104.802042”);

DataSet set = new DataSet(“StateCapitals”);


Creating the Map: WPF Bing Map Part 2


Now start a new wpf project in visual studio. I am using c#, but most of this is easy to transfer over to vb. Once you have downloaded the map control you must reference in in visual studio.  To do that you right click on References in Solution Explorer  and select add reference.  Then select the path (using browse), to where you installed the control.   Then of course you’ll need to add; using Microsoft.Maps.MapControl.WPF; to your c# sharp code and xmlns:m=”clr-namespace:Microsoft.Maps.MapControl.WPF; assembly=Microsoft.Maps.MapControl.WPF” to the xaml code.

Adding the map is then as simple as adding the xaml code:

<m:Map x:Name=”myMap” CredentialsProvider=”Put You Key Here” Mode=”Road” Center=”35.665600,-95.469700″ ZoomLevel=”3″>

This will add a map to your wpf window. In part 3 we add data to our map, using the default pushpins.

Using the Bing Map API


When you start using the Bing Map API the first thing you run into is information overload.

You have to make a decision on which API’s your going to need for your project. For my project I will using the Bing Maps WPF control.  This requires you get A Bing Maps key to do this you must go to Microsoft and register you will be given a key that you can use for your map.   The next step is to down load the the WPF control;

Now we are ready to start making a map in visual studio.

The love of maps.

As a little boy I really enjoyed maps.  I would take long walks through the woodtatics2 surrounding  my house and later would draw out what I saw as a notebook ruled paper map.  I always enjoyed creatively naming the logs ditches and streams.  Dead mans run for a stream or run and jump off log or what ever I could dream up.  In my early teens my cousin and I started playing the strategic war games,  that where being produced by Avalon Hill.   What could be better than play a game that combined two of my favorite things maps and war.  Later I would play simple computer versions of those games on my  Commodore 64.  And of course typing those games from magazines taught me the basics of programming.  When I got to the University many years later I found that Geography majors got to draw maps using computers. Granted the computers where Apple II e’s and the program used a basic spread sheet format.  I became a Geographic Information Systems person.  Then things began to change,  technology made it possible for anybody to create maps using GPS and simple point and click computer programs.   I retreated back into my programming world.   In .Net Framework 3.0 Microsoft gave us a wonderful gift called the Windows Presentation Foundation. Using this and the Bing Map API I can now create maps to display my data.  All though its usually over kill for my purposes it gives me a chance to combine two of my loves.  I am not an expert but because I believe the best way to learn is to teach, (Cory House again). I’m going to describe how one goes about writing a mapping application for the desktop using WPF, C# and the Bing map API. In my next post. Please be kind.

Training The Old Dog

img_0005As I get older I find it is more difficult to retain information.   I think that’s a standard effect of aging.  But something that I also have noticed is that I have a increased capacity to reason out the solution to a problem.  I have been doing plurasight training  and have notice that I can answer the practice test questions many times without knowing the material.  What I am really doing is reasoning out the logic of the question.   This kind of defeats the purpose of a practice test.  But on the other hand it does help when I am face with a difficult problem.  In my younger days I would have approached problem by using the “shot gun approach”. You know old try everything you can think of until you find one that works. I find this in  my older code. Sometimes I find  a method that seems to have no real reason to exist.  I assume that I must have been chasing a rabbit, that went no where useful. I am generally very careful in deleting these, in that I am often smarter than I think I am and these snippets have a purpose that are not obvious.

First post.

Some days I have the thrill  of starting a new software project.  I get to figure out the best technology, design the databases, start coding  the xaml, you know all the fun stuff. Other days I am required to solve a problem fast and program some crap in order to satisfy a need. You know the development triangle.  Related imageBut inevitably I have to go back and try to clean up the fast and cheap of the original code. Today is such a day.  I  needed to clean up and document a program written in C#, in order to solve a business problem.  It would take to much effort to explain the problem or task, and my program does solve the problem.  But the code lacks efficiency, breaks most of the rules of object orient programming and is just plain ugly.   The code works fine and task is accomplished, but as some who aspires to be as Cory House puts it an “Outlier”. I really must fix it.