Community of VE/MapPoint Users and Developers
This is a discussion on Snap to a Road within the MP2K Magazine Articles forums, part of the Map Forums category; Snap to a Road Wilfried Mestdagh's article shows how to take a lat/lon and find the nearest road ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Snap to a Road Wilfried Mestdagh's article shows how to take a lat/lon and find the nearest road relative to that point. The technique, written entirely in Delphi, employs reverse geocoding and determines the lat/lon using a CalcXY routine. Read the full article here -- http://www.mp2kmag.com/a130--snap.ca....mappoint.html Post a comment by clicking Post Reply above.
__________________ Order MapPoint 2006 | Read Programming MapPoint in .NET | Start Using the Pushpin Tool - Free Trial Download - click here. |
| |||
|
Hello wilfried ! First of all, thanks so much for your effort on the article ! Im pretty new with Delphi, so i was wondering if u could give me some help, in using your code. I don't understand what your function expects with : (ErrorProc: TOnError) This is what i have done sofar : - Saved your code to mp.pas - Made a new project and added mp.pas to the project. procedure TForm1.Button1Click(Sender: TObject); var mpx : TMapPoint; d1, d2 : Double; st : TStrings; sx : String; i : Integer; begin d1 := StrToFloat(Edit1.Text); d2 := StrToFloat(Edit2.Text); mpx.Create(); //<-- What to put here ? mpx.GetStreetAddr(d1,d2,st,sx,i); mpx.Destroy; end; I have no clue what to put behind mpx.Create(?). Is the rest of the code the good way ? Would u be do kind to help me (Or anyone else). I would love to see this working. Once again, thanks for the article ! Regards |
| |||
|
Hi Robin, In the constructor you give a callback function so if the component generates an exception this callback function can log it. You can give also nil to it then nothing is called back. I made a small testproject to demonstrate how to use it. Create a new project, add a new unit and copy the code in it as you alrady have done. Call the form TMain, add a button to the form and call it TestBtn. Then add the following code: Code: procedure TMain.FormCreate(Sender: TObject);
begin
AllocConsole;
end;
// This is a callback function.
// Just in case mappoint produces an exception then we can display it
procedure TMain.MPError(Sender: TObject; E: Exception);
begin
WriteLn(E.ClassName + ' ' + E.Message);
end;
procedure TMain.TestBtnClick(Sender: TObject);
var
MP : TMapPoint;
Lat, Lon: Double;
Streets: TStrings;
Street, Direction: string;
Distance: integer;
n: integer;
begin
Streets := TStringList.Create;
MP := TMapPoint.Create(MPError);
try
Lat := 51.2497;
Lon := 4.4888;
MP.GetStreetAddr(Lat, Lon, Streets, Direction, Distance);
if Streets.Count = 0 then begin
WriteLn('No match found');
Exit;
end;
// We can have more than 1 streetname in the stringlist.
// In most cases the longest name is the most detailed
// So we display only the most detailed.
Street := '';
for n := 0 to Streets.Count - 1 do
if Length(Streets[n]) > Length(Street) then
Street := Streets[n];
WriteLn('Point is ' + IntToStr(Distance) + ' meter ' + Direction + ' from ' + Street);
finally
MP.Free;
Streets.Free;
end;
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
|
Hi Wilfried, One more question It seems the Country information is missing from the Street information. Is this caused by MapPoint self, or is there another way to show the country information togheter with the found adres ? (e.g. ..... Amsterdam - Netherlands) Thanks again ! Regards, Robin. |
| |||
|
Hi Robin, StreetAddress has a Country property. Probably not includeded in the Value property. I think it is easy to add. Use Country propretyand add it to the value to see.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
|
Hello Wilfried, When reverse geocoding, if a point is not on a road, I keep increasing the altitude until it falls onto a road(I limit the max altitude to 15). Your technique looks interesting. Is it more efficient or better than increasing the altitude ? Because if so, I can give it a try(I need to convert your code to C#). Thanks |
| |||
| Thanks!
Thanks! This article combined with Gilles Kohl's article definitely gave me a jump start on getting reverse geocoding going. I combined the two approaches and added some additional features (making it behave a little like a heuristic search algorithm and trying to make sure we spend our time as well as possible). One *duh* moment I had that can save anyone time that thinks as slow as I do: make sure your map is zoomed in to the right level of detail! MapPoint gives you a lot better results when you do |
![]() |
| ||||
| Posted By | For | Type | Date | |
| Google Groups: microsoft.public.mappoint | This thread | Refback | 12-17-2006 06:11 PM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Snap to Road Feature duplicated | douglashawkins | MapPoint 2006/2009 Discussion | 3 | 03-23-2005 12:36 PM |
| mappoint snap to road | Omair | MapPoint 2006/2009 Discussion | 1 | 12-25-2004 06:44 AM |
| MS Snap files | surferj | MapPoint 2006/2009 Discussion | 4 | 05-28-2003 02:54 PM |
| I need to map an off road trail | Anonymous | MapPoint 2006/2009 Discussion | 2 | 04-20-2003 09:54 PM |
| How can I find nearest point on a road from a point off-road | Anonymous | MapPoint 2006/2009 Discussion | 1 | 11-12-2002 06:14 AM |
Ski Holidays French Alps
Ski holidays in the French Alps are a unique and exciting experience. There are a great range of resorts which are great value when you book with Holiday Hypermarket online.
Cruise Travel Agent
Book your cruise with Travel Counsellors. We are an award winning travel agent and can help plan your perfect cruise.
Jamaica Holiday
Fancy a Jamaica Holiday? Then visit dealchecker.co.uk and find out what the big deal is. Book a bargain when you book online.
Holidays to St Lucia
Holidays to St Lucia will leave you smiling. The spectacular scenery and the warmth of the locals make holidays to St Lucia unforgettable.
Tunisia
Tunisia enjoys excellent weather, golden beaches and a beautiful blue sea. Moving away from the beach you will find a country that has a rich and varied past. Discover the secrets of history yourself by exploring all the ruins.
Bargain Holidays
To plan your holidays at bargain prices, use Travel.co.uk to explore all the possibilities.
Portugal Holidays
We specialise in Portugal holidays. Visit our On The Beach website for more information.