Community of VE/MapPoint Users and Developers
This is a discussion on Importing LatLongs and postcodes from excel within the Development forums, part of the MapPoint 2006/2009 Discussion category; I am using c# to write an application to import postcodes and latlongs from excel and access and then create ...
| |||||||
| 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 MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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 MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
![]() |
| Tags |
| excel, importing, latlongs, postcodes |
| ||||
| Posted By | For | Type | Date | |
| Reverse Geocoding with MapPoint 2002 - MapPoint Articles - MP2K Magazine | This thread | Refback | 07-08-2008 02:41 AM | |
| Reverse Geocoding, Another Method - MapPoint Articles - MP2K Magazine | This thread | Refback | 07-08-2008 02:39 AM | |
| More on reverse geocoding, MapPoint on MSDN, and contest round-up - MP2K Update Archives - MP2K Magazine | This thread | Refback | 07-08-2008 02:36 AM | |
| Routene Excel and MapPoint Update - MapPoint Articles - MP2K Magazine | This thread | Refback | 07-07-2008 12:07 PM | |
| Formatting Coordinates with DmsFormat - MapPoint Articles - MP2K Magazine | This thread | Refback | 07-05-2008 02:13 AM | |
| Reverse Geocoding, Pt. III - MapPoint Articles - MP2K Magazine | This thread | Refback | 07-02-2008 06:35 AM | |
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 2006/2009 Discussion | 3 | 11-01-2007 09:48 AM |
| Mappoint importing with excel error | Raian | MapPoint 2006/2009 Discussion | 1 | 10-23-2007 08:48 AM |
| importing data from excel to mappoint | Layne | MapPoint 2006/2009 Discussion | 0 | 05-09-2003 12:40 PM |
| importing excel file into mappoint | misterb83 | MapPoint 2006/2009 Discussion | 2 | 04-14-2003 01:56 AM |
| When importing from MS Excel .csv files into MapPo.... | Anonymous | MapPoint 2006/2009 Discussion | 1 | 08-08-2001 07:35 AM |
Cheap Ski Holidays Canada
Book cheap ski holidays to Canada online at Holiday Hypermarket. Why not use our simple ski holiday search to find the cheapest deals?
Flights to Spain
Find cheap flights to Spain on Travel Counsellors. A personal Travel Counsellor can help you plan flights and find accommodation in Spain.
Cheap Flight Canada
Making a cheap flight to Canada can become a reality when you book online with dealchecker.co.uk. Our simple search allows you to see for yourself who is the cheapest.
Holidays to Cuba
For the best offers on holidays to Cuba, visit The Holiday Place today. Find a deal to suit you and your budget online!
Turkey
Before booking a holiday to Turkey check out the ULookUBook travel guide. Find out about the rich culture in Turkey before you go there to help you to make the most of your holiday.
Holiday
For the holiday of your life, that is easy to plan, visit Travel.co.uk to see all the options.
Cheap Holidays in Fuerteventura
Save your money! Live like royalty! Visit the Canary Islands! Get info on cheap holidays in Fuerteventura, only at On The Beach.