Community of MapPoint and Virtual Earth Users and Developers
This is a discussion on What happens when YOU click on a street? within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; I'm using MP2002 (Europe). When I click on a street I usually get the streetname and postal code for it. ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| What happens when YOU click on a street? Any comments are welcome. Pascal |
| |||
|
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. |
| |||
|
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 |
| |||
| it DOES work!
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. |
![]() |
| Tags |
| click, street |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Where did I click on that line? | Jumbly | MapPoint 2006/2009 Discussion | 3 | 12-08-2004 03:53 AM |
| Long/Lat from click. | Milo | MapPoint 2006/2009 Discussion | 7 | 10-29-2004 07:32 AM |
| Double Click on a Pushpin | Anonymous | MapPoint 2006/2009 Discussion | 4 | 02-28-2004 06:26 PM |
| How to add click event for VB.Net ? | Anonymous | MapPoint 2006/2009 Discussion | 2 | 12-31-2003 12:15 AM |
| Double Click on map | Anonymous | MapPoint 2006/2009 Discussion | 0 | 08-08-2003 06:42 PM |
Corfu Holiday
Why not enjoy the option of a Corfu holiday through UlookUbook? Check out the online offers...