Community of MapPoint and Bing Maps Users and Developers
This is a discussion on Importing LatLongs and postcodes from excel within the Development forums, part of the MapPoint Desktop Discussion category; I am using c# to write an application to import postcodes and latlongs from excel and access and then create ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Importing LatLongs and postcodes from excel Stop Number, Postcode, Latitude, Longitude. The stop number is mandatory. Each record will have either the postcode or the lat longs but not both. I use the following code to process the data Code:
DataSet ds = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, conn);
adapter.Fill(ds);
conn.Close();
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
MapPoint.Location loc = null;
string postCode = (dr["Postcode"].ToString());
string lat = (dr["Latitude"].ToString());
string lon = (dr["Longitude"].ToString());
object result = new object();
if (postCode.Equals(""))
{
double dblLat = System.Convert.ToDouble(lat);
double dblLon = System.Convert.ToDouble(lon);
result = axMappointControl1.ActiveMap.GetLocation(dblLat, dblLon, 1);
}
if (lat.Equals(""))
{
result = axMappointControl1.ActiveMap.ShowFindDialog(postCode, MapPoint.GeoFindState.geoFindDefault, 0, true);
}
if (result is MapPoint.Location)
{
loc = result as MapPoint.Location;
if (loc != null)
{
MapPoint.Pushpin pushpin = axMappointControl1.ActiveMap.AddPushpin(loc, loc.Name);
}
}
else if (result is MapPoint.Pushpin)
{
MapPoint.Pushpin found = result as MapPoint.Pushpin;
loc = found.Location;
}
else
{
MessageBox.Show("No location found");
}
This is ok if the whole import file only contains either latlongs or postcodes. If it contains both, i have seen it work through the data table of postcodes and when it finds a blank postcode it is not passing a the latitude or longitude into the variable. Im a noob at C# so i must be doing something wrong. Any help would be much appreciated. |
| |||
| Re: Importing LatLongs and postcodes from excel
Hi, Quote:
You also tell that if data does not contain a mixture then it works. Did you tried this with exactly the same data as the mixture one?
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz www.comfortsoftware.be www.expertsoftware.be MapPoint coding demo |
| |||
| Re: Importing LatLongs and postcodes from excel
Hi I will try to explain better. I have been trying to post an example of my in HTML but i cant so i will try and describe it better. The table has four columns, 1. Stop Number 2. Postcode 3. Latitude 4. Longitude The stop number column is manadatory, this is like the primary key. Each stop number will have either a postcode or latitude and longitude. It will not have both. The code looks to see if the Stop number has a postcode, if it doesnt have a postcode it should look at the latitude and longitude. If i am importing the table from Access everything works fine. The issue is if im importing from excel. For example, Stop number = 1, Postcode = B65 4RT, lat = "", long = "" outcome = stop added to route. stop number = 2, Postcode = B67 6YH, lat = "", long = "" outcome = stop added to route. Stop number = 3, Postcode = "", Latitude = 52.6666, Longitude = -2.6777. outcome = stop not found. When you look at the code in debugging mode it shows that string lat and string lon have not been assigned the value from the column. It seems to be that if the last data that was processed was from the postcode column, it is not picking up the data from the latitude and longitude columns for the next data row if the postcode = "". Not sure if this is any clearer but hope it provides a better explanation. It would be easeier if i could post html. Thanks for your help |
| |||
| Re: Importing LatLongs and postcodes from excel
Hi, thanks for clarify. So it is an Excel problem. I see nothing wrong at your code at first sight, but I never done something in Excel. Hope someone with more Excel insight drops in here.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz www.comfortsoftware.be www.expertsoftware.be MapPoint coding demo |
![]() |
| Tags |
| excel, importing, latlongs, postcodes |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting stops when importing from excel? | zb61 | MapPoint Desktop Discussion | 3 | 11-01-2007 08:48 AM |
| Mappoint importing with excel error | Raian | MapPoint Desktop Discussion | 1 | 10-23-2007 08:48 AM |
| importing data from excel to mappoint | Layne | MapPoint Desktop Discussion | 0 | 05-09-2003 12:40 PM |
| importing excel file into mappoint | misterb83 | MapPoint Desktop Discussion | 2 | 04-14-2003 01:56 AM |
| When importing from MS Excel .csv files into MapPo.... | Anonymous | MapPoint Desktop Discussion | 1 | 08-08-2001 07:35 AM |