PDA

View Full Version : MapPoint 2002 - Reverse Address Lookup's in Delphi..



David
08-19-2002, 08:46 AM
I'm having loads of problems trying to reverse look-up addresses, i.e. the user provides just the Postcode or Street+Town I then want to fill in the missing values; say if the user provides just a postcode I want to be-able
to extract the Street, Locality, Town, County etc.. from MapPoint.

I've had a go using both Location.FindNearby and Map.ObjectsFromPoint; but when I try and access a StreetAddress object from within the results I get an exception error even if the original request already had a Street Name, Town, Postcode etc. :-(.

I think I'm just chasing my own tail here im sure there is a problem with the OLE/ActiveX interface :-(

Anybody got any ideas?

Regards,

David Luck.

John Meyer
08-19-2002, 05:57 PM
Have you tried the ShowFindDialog method?

David
08-20-2002, 03:10 AM
I have not used the ShowFindDialog method but at a guess I would say that actually "displays" a dialog requiring user input, the problem is this is part of a Server system and the MapPoint objects are contained in a Thread so no direct user input is possible.

John Meyer
08-20-2002, 06:29 AM
Ok, I'm confused. I think you would need to discribe what you are doing a little more or at least post the code that is not working.

In the first post you said a user might only enter a postcode and you want to "extract the Street, Locality, Town, County etc" Do you have pushpins already on the map that you are trying to find the best match for?

David
08-20-2002, 06:51 AM
Ok here goes :)

We develop a control system for transport companies, at present each client PC has a copy of MapInfo installed and all Mapping, routing and postcode look-ups are done locally. Trouble is this means the client machines need to be pretty well spec'ed to actually make the system usable.

This is where MapPoint comes in, we have decided to opt for a Client/Server type Mapping system where the client systems (users) just post requests to a mapping server (very high-spec machine) which in-turn queries MapPoint for a Map, Route or address look-up, the server then returns an XML response to the client.

I have written the server product in Delphi and it has been designed as a multi-threaded application, so the MapPoint objects are self contained in their own thread and there-fore are only accessed when a request is to be processed, this means the system is stand alone and it is not possible for any direct user input into the MapPoint components, also all MapPoint COM/ActiveX objects are created and accessed at code level so there is no visible representation of MapPoint on the server.

John Meyer
08-20-2002, 08:05 AM
Can you post the sub/function where you try and access the streetaddress as you discribed so I can try a few things with it?

"but when I try and access a StreetAddress object from within the results I get an exception error even if the original request already had a Street Name, Town, Postcode etc."

David
08-20-2002, 08:29 AM
This is'nt "exactly" what tried, but it was something along these lines:

mpLocation is the location from which I want to find the nearest Street, lets say for example the postcode for mpLocation is 'RG6 3XA'.

Note mpMap is a Public Object of TMap (MapPoint Map).



//mpLocation is the location we are trying to reverse look-up, the result/output
//(TLocation) is a custom object containing address information: street, town etc.
function TMapPointThd.FindNearestStreet(mpLocation : Location) : TLocation;
var
mpResults : FindResults;
iResult : Integer;
oleCount : oleVariant;
oleResult : oleVariant;

begin

//Not sure exactly what this does but im told its nessessary??
mpLocation.GoTo_;

//Convert the given locaton to X and Y co-ord's on the map.
mpResults := mpMap.ObjectsFromPoint(mpMap.LocationToX(mpLocatio n),mpMap.LocationToY(mpLocation));

//Use an oleVariant object to store the number of results.
oleCount := mpResults.Count;

//do we have any results?
if (oleCount > 0) then
begin
//loop through all the results.
for iResult := 1 to oleCount do
begin
//Another ole variant is required to read the results so we convert the
//integer iResults to an oleVariant type.
oleResult := iResult;

//Make sure the result is not nil.
if &#40;mpResults.Item&#91;oleResult&#93; <> Nil&#41; then
begin
//Look up the street name..
Result.Street &#58;= Location&#40;mpResults.Item&#91;oleResult&#93;&#41;.StreetAddress. Street;
end;
end;
end;
end;

John Meyer
08-20-2002, 01:06 PM
David,

There is NOT an easy way to do what you are trying to do (That I can see): ie just using a postcode and reterning the closest street.

About the most I could get the StreetAddress property to do was return the City if that was the only thing I omitted when I used FindAddressResults to get my Location object..

I think that when you tried to get a location object ("even when the original request already had a street name") the reason you got an error was Mappoint did not have enough info to get a match and returned Nothing. in other words when you tried to use the objLocStreetAddress.Street (or whatever) your objLoc was Nothing.

FindNearby method results are limited to the currently visible PlaceCategory objects (Like Restaurants, Airports etc..) So that wouldn't work even if you have a good location object.

Sorry I couldn't be of more help. If anyone else has an idea feel free to jump in!

John Meyer
08-20-2002, 02:39 PM
Check out this article:

Reverse Geocoding, Pt. III
Walt Cygan, a frequent contributor of late, submits this solution for tackling reverse geocoding

http://www.mp2kmag.com/articles.asp?ArticleID=50

"I use the ObjectsFromPoint method repeatedly at slightly different locations to attempt to find an address. "

Eric Frost
08-20-2002, 04:05 PM
As the Pt. III suggests, there were a couple articles before then.. http://www.mp2kmag.com/mappoint/discussion/viewtopic.asp?t=2966

David
08-21-2002, 03:26 AM
Nightmare :( we have only decided to use MapPoint on the assumption that it could handle post-code/reverse look-ups..

David
08-21-2002, 05:31 AM
Thanks for the response peeps :)

Has anyone got an example without any underlying features i.e. a function that has been written specifically to do the job of reverse look-ups, its hard enough translating VB code to Delphi it just makes it 10 times harder when there is a load of irrelevant code :(

David
08-21-2002, 08:31 AM
Update :(

I spent a bit of time this afternoon translating the above function from VB to Delphi, and im encountering the same problem, in the VB code you are able to access FindResults.Item[i].StreetAddress but in Delphi you must typecast the FindResults.Item[i] as a Location type BUT when I type case an Item from FindResults as Location it throws an exception:

e.g. "(Location(mpResults.Item[oleItem]).StreetAddress"

I believe this is due to the fact that FindResults can contain objects other than Location and the item I am attempting to type cast is not of Location type, trouble is Delphi does not allow me to do use standard "IS object of Type" expression with these objects :(

I have even started to think about resorting to API calls to the MapPoint application but thats going to be a nightmare due to the threaded nature of this application.

Double Doh!

David
08-21-2002, 10:44 AM
Since my last post I have actually made some significant progress :) I've used Walt Cygan idea of taking two points on the globe and using them as a cross section to work out the Lat/Long of a given location, I have then used this Lat/Long to find the nearest Road which I can then obtain the needed details from.

Im a happy bunny yet again :)