MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Snap to a Road

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 ...


Go Back   MapPoint Forums > Map Forums > MP2K Magazine Articles

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-12-2006
Eric Frost's Avatar
Administrator
Black Belt
 
Join Date: Jul 1992
Posts: 2,210
Blog Entries: 1
Snap to a Road

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 03-06-2006
Junior Member
White Belt
 
Join Date: Mar 2006
Posts: 4
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 03-06-2006
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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;
Compile it and correct my typo's in the class There are some points where I typed >:= wich must be >= of course
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 03-06-2006
Junior Member
White Belt
 
Join Date: Mar 2006
Posts: 4
Wilfried !

You made my day It's working flawless !

Thank you so much for your article and your help !

Regards

Robin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 03-06-2006
Junior Member
White Belt
 
Join Date: Mar 2006
Posts: 4
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 03-07-2006
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 03-08-2006
Junior Member
White Belt
 
Join Date: Mar 2006
Posts: 4
Hello Wilfried !

Oke, thanks ! Im going to check it out

Cheers

Robin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 04-28-2006
Junior Member
White Belt
 
Join Date: Apr 2006
Posts: 2
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 05-23-2006
MR MR is offline
Junior Member
White Belt
 
Join Date: May 2006
Posts: 1
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 .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 06-16-2006
Junior Member
White Belt
 
Join Date: Jun 2006
Posts: 1
Would anyone have any suggestions for snapping to a road using the map point web service? Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/snap-road-4768.html

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 04:25 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47