PDA

View Full Version : What happens when YOU click on a street?



schuchhardp
12-11-2002, 03:46 AM
I'm using MP2002 (Europe). When I click on a street I usually get the streetname and postal code for it. Somethimes I get the housenumber. However, for streets residing in the Netherlands, I NEVER get the postal code. I would like to know if people experience the same result that I get (no postal codes for the Netherlands). Does anyone know the reason for this?

Any comments are welcome.

Pascal

yelmaci
12-11-2002, 04:09 AM
Hi pascal,

See next post

yelmaci
12-13-2002, 06:39 AM
Please find here the required function to find NL post codes.

nlpostcodefinder is the main function. Requires 2 parameters.

1st : street name,
2nd: city name.

and returns back the postcode.


Pls: this is just for NL. For other countries, already possible to get the postcode directly via FindAddressResult of location.

Pls: Put 3 edit boxes to a form(formname : form1). names are: city, street,postcode. And lastly, add a button. its name is Button1.


Regards.
----------------------------------------------------------

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, OleServer, MapPoint_TLB;

type
TForm1 = class(TForm)
Map11: TMap1;
street: TEdit;
Label1: TLabel;
city: TEdit;
Label2: TLabel;
Button1: TButton;
postcode: TEdit;
Label5: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
locNorthPole:Location;
locSantaCruz:Location; //Center of western hemisphere
Pi, dblHalfEarth, dblQuarterEarth:double;
function Arccos(x:double):double;
function GetLat(locx:Location):double;
function GetLon(locx:Location):double;
function nlpostcodefinder(pstreet,pcity:string):string;
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
//------------------------------------------
function TForm1.Arccos(x:double):double;
var
ret:double;
begin
if x=1 then
ret:=0
else
ret:=ArcTan(-x/Sqrt(-x*x+1))+2*ArcTan(1);
result:=ret;
end;
//--------------------------------------------

function TForm1.GetLat(locx:Location):double;
var
ret:double;
begin
ret:=90 - 180 * map11.Distance(locNorthPole, locX) / dblHalfEarth;
result:=ret;
end;


function TForm1.GetLon(locx:Location):double;
var
ret, l , d , lat:double;
begin
lat:=GetLat(locx);

d:= map11.Distance(map11.GetLocation(lat, 0, 0), locX);

l:= (Lat / 180) * Pi;

ret:= 180 * Arccos((Cos((d * 2 * Pi) / (2 * dblHalfEarth)) - Sin(l) * Sin(l)) / (Cos(l) * Cos(l))) / Pi;

If map11.Distance(locSantaCruz, locX) < dblQuarterEarth Then ret:= -ret;

result:=ret;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
locNorthPole:=map11.GetLocation(90,0,0);
locSantaCruz:=map11.GetLocation(0,-90,0);
dblHalfEarth:=map11.Distance(locNorthPole, map11.GetLocation(-90, 0,0));

dblQuarterEarth:=dblHalfEarth/2;
Pi:=3.14159265358979;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
postcode.Text:=nlpostcodefinder(street.text,city.t ext);
end;

//---------------------
function TForm1.nlpostcodefinder(pstreet,pcity:string):stri ng;
var
street1,city1,postcode1:widestring;
frs,frs2,frs3:findresults;
la,lc,l:location;
nl,o:olevariant;
i:integer;
str,ret1:string;
dist:double;
lat1,long1,lat1x,long1x:double;
label loop1;
begin
ret1:='NotF';
nl:=176;
street1:=pstreet;
city1:=pcity;

frs:=map11.FindAddressResults(street1,city1,'','', '',nl);
if frs.Get_Count>0 then
begin
o:=1;
la:=frs.Get_Item(o) as location;

lat1:=GetLat(la);
long1:=GetLon(la);


//////////////////////////////
l:=map11.GetLocation(lat1,LONG1,0);
dist:=0.5;

loop1:
frs2:=l.FindNearby(dist);


for i:=1 to frs2.Get_Count do
begin
o:=i;
lc:=frs2.Get_Item(o) as Location;

try
str:=lc.StreetAddress.Get_Street;
//-------------------POSTCODE CONTROLL------------------------------
postcode1:=Copy(str,1,4);
if pos(UpperCase(city1),Uppercase(str))>0 then
begin
city1:=Copy(str,6,100);
frs3:=map11.FindAddressResults(street1,city1,'','' ,postcode1,nl);
if frs3.Get_Count>0 then
begin
o:=1;
la:=frs3.Get_Item(o) as location;
lat1x:=GetLat(la);
long1x:=GetLon(la);
if (lat1x=lat1) and (long1x=long1) then
begin
ret1:=postcode1;
break;
end;
end;

end;
//-------------------------------------------------
except
on e:exception do begin end;
end;
end;
end;
if ret1='NotF' then
begin
dist:=dist+0.5;
goto loop1;
end;
result:=ret1;
end;

end.

schuchhardp
12-16-2002, 03:37 AM
Yıldıray,

Thanks very much for you help. I copied your code but I can't get it to work: I get an access violation on frs:=map11.FindAddressResults(street1,city1,'','', '',nl);

I haven't been able to get the activeX control in Delphi as you described in MP2K magazine, so I added to the var section of the program the following:
MyInterface : _Application;
map11 : _Map;

And to the beginning of FormCreate the following:
MyInterface:=CoApplication.Create;
map11:=MyInterface.ActiveMap;

Can these alterations cause the problem and how can I get the activeX control of MP in Delphi?

Again, thanks very much for your help. This is a really big problem for me.

Pascal

schuchhardp
12-23-2002, 05:14 AM
Mmm, I reinstalled Delphi and now this solution does work. Guess I did something wrong with the installation of the ActiveX components.

Thanks a lot!

By the way, I have contacted Microsoft about this issue and they admit tihs is a bug. They don't think they will fix it before the next release of MapPoint.

Anonymous
01-03-2003, 10:37 AM
Unfortunately, this solution does not work in all parts of the Netherlands, I just noticed. This is a really nasty problem.