sf_bbl
03-09-2008, 04:03 PM
Hello,
I'm new user of visual studio and mappoint, I need to get the list of all cities with the postcode and the distance from a city. Do you think I can do that ? I need to do it with mappoint because all of my parterns work with it.
Have you some samples ?
Wilfried
03-10-2008, 08:40 AM
Hi,
Yes you can do that. you have to scan the map at regular distance and make a list of the places with their location. after you have build the list, filtered out duplicates and so, then you can use DistanceTo method to find the distance from all of them to the other.
sf_bbl
03-10-2008, 10:16 AM
I am a very dummy, I never code in vb. Can you give some samples, please ?
Wilfried
03-10-2008, 10:37 AM
Hi,
this class written in C# find streets in a selected area. You can do the same with postcodes for you application. You have to translate it into the programming language of you choice.
public partial class FindStreetsInArea : Form
{
private Timer timer;
private const double ALTITUDE = .5;
private const int INCREMENT_METER = 75; // we do a check every 75 meter
private double startLat, startLon;
private double currentLat, currentLon;
private double lonInc;
private const double latInc = (double)INCREMENT_METER / 1000 / 1.852 / 60;
private int x, y, maxX, maxY;
private StringBuilder street = new StringBuilder();
public FindStreetsInArea(GeoMapRegion mapRegion, double centerLat, double centerLon, double width, double height)
{
InitializeComponent();
MP.NewMap(mapRegion);
timer = new Timer();
timer.Tick += timer_Tick;
timer.Interval = 1;
timer.Enabled = true;
double nauticalMilesHeight = height / 1.852; // heigth and width are in km
double nauticalMilesWidth = width / 1.852; // so we convert to nautical miles
startLat = centerLat + nauticalMilesHeight / 2 / 60;
startLon = centerLon - nauticalMilesWidth / 2 / 60 / Math.Cos(centerLat);
maxX = (int)(width * 1000 / INCREMENT_METER);
if (maxX == 0)
maxX++;
maxY = (int)(height * 1000 / INCREMENT_METER);
if (maxY == 0)
maxY++;
lonInc = INCREMENT_METER / Math.Cos(centerLat) / 1000 / 1.852 / 60;
currentLat = startLat;
progressBar.Maximum = maxX * maxY;
x = 0;
y = 0;
}
void timer_Tick(object sender, EventArgs e)
{
timer.Enabled = false;
try {
if (x == 0)
currentLon = startLon;
currentLon += lonInc;
findStreets();
triggerPosition();
progressBar.Increment(1);
x++;
if (x == maxX) {
x = 0;
y++;
if (y > maxY) {
// We are done
timer.Dispose();
progressBar.ForeColor = Color.Lime;
return;
}
currentLat -= latInc;
}
timer.Enabled = true;
} catch { // Application could have been terminated
}
}
/// <summary>
/// Remove leading and trailing numbers
/// Filters out duplicate streets
/// Filters out streetnames length <= 3 characters, eg: N, E, A, Tel, Fax
/// </summary>
public void findStreets()
{
Map map = MP.ActiveMap;
map.Altitude = ALTITUDE;
Location loc = map.GetLocation(currentLat, currentLon, ALTITUDE);
loc.GoTo();
FindResults streetResults = map.ObjectsFromPoint(map.LocationToX(loc), map.LocationToY(loc));
foreach (object o in streetResults) {
Location StreetLoc = o as Location;
if (StreetLoc != null && StreetLoc.StreetAddress != null) {
street.Length = 0;
int n = 0;
while (n < StreetLoc.StreetAddress.Street.Length) {
if (StreetLoc.StreetAddress.Street[n] >= 'A')
break;
n++;
}
while (n < StreetLoc.StreetAddress.Street.Length) {
if (StreetLoc.StreetAddress.Street[n] >= '0' && StreetLoc.StreetAddress.Street[n] <= '9')
break;
street.Append(StreetLoc.StreetAddress.Street[n++]);
}
string streetTrimmed = street.ToString().TrimEnd(new char[] { ' ', ',', '.', ':' });
if (streetTrimmed.Length > 3 && listBox.FindString(streetTrimmed) < 0)
listBox.Items.Add(streetTrimmed);
}
}
}