Getting a Postal Sector from Latitude and Longitude

Yazzy
08-29-2005, 05:41 PM
Hi

I have ONLY the Longitude and Latitude of a place and I need a way to find the PostalCode for the place. No dataset avaiable

For example Lat = 52.0185 Long = -0.2654
Set objLoc = objmap.GetLocation(Latitude, Longitude)
objLoc.GoTo

Set objPin = objmap.AddPushpin(objLoc)
objPin.Select

I get the pushpin at the correct place on the map. But when I use the

Set objResults = objmap.ObjectsFromPoint(objmap.LocationToX(objLocA ), objmap.LocationToY(objLocA))

For Each objResult In objResults
MsgBox objResult.Name
Next

I get incorrect results i.e 'Luton', Sandy Roundabout etc when the correct results should be Chase Hill Road, Arlesey, SG15 6.

When I fire a MouseDown event around the pushpin I do get House Number, Chase Hill Road, Arlesey, SG15 6.

i would like to know how I can capture this without firing MouseDown events.

Thanks in advance

PS
I have also tried the following method and I get errors of 'Type Mismatch' Or 'Object does not support this method etc

Map map = MP.ActiveMap;
Location loc = map.GetLocation(lat, lon, 1);
FindResults nearby = loc.FindNearby(1);
foreach (object o in nearby) {
loc = o as Location;
if (loc != null && loc.StreetAddress != null && loc.StreetAddress.PostalCode != "") {
return loc.StreetAddress.PostalCode;

Wilfried
08-30-2005, 02:26 AM
Hi,

I just tryed this exact code in a menu item and it gives me a post code:

private void postcodefromlatlongToolStripMenuItem_Click(object sender, EventArgs e)
{
Map map = MP.ActiveMap;
Location loc = map.GetLocation(51, 4, 1);
FindResults nearby = loc.FindNearby(5);
foreach (object o in nearby) {
loc = o as Location;
if (loc != null && loc.StreetAddress != null && loc.StreetAddress.PostalCode != "")
Console.WriteLine(loc.StreetAddress.PostalCode);
}
}

FindNearby does not find always a postcode. This is because it is designed to search for points of interest which does not nececary have a postal code. Another way is scan the map in code with a vector until you have a postal code.

Wilfried
08-30-2005, 02:46 AM
Hi,

I tryed your original code as whell and it works. Only your coordinates are not right, it has to be: loc = map.GetLocation(52.0185, -0.2653, 1);

Longitude -0.2654 is not on a road, so map cannot give you information. You have to be at least on a known object.

 
Web mp2kmag.com
mapforums.com