Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

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

  1. #1
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    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 MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  2. #2
    RobinX is offline 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

  3. #3
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    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&#40;Sender&#58; TObject&#41;;
    begin
       AllocConsole;
    end;
    
    // This is a callback function.
    // Just in case mappoint produces an exception then we can display it
    procedure TMain.MPError&#40;Sender&#58; TObject; E&#58; Exception&#41;;
    begin
       WriteLn&#40;E.ClassName + ' ' + E.Message&#41;;
    end;
    
    procedure TMain.TestBtnClick&#40;Sender&#58; TObject&#41;;
    var
       MP &#58; TMapPoint;
       Lat, Lon&#58; Double;
       Streets&#58; TStrings;
       Street, Direction&#58; string;
       Distance&#58; integer;
       n&#58; integer;
    begin
       Streets &#58;= TStringList.Create;
       MP &#58;= TMapPoint.Create&#40;MPError&#41;;
       try
          Lat &#58;= 51.2497;
          Lon &#58;= 4.4888;
          MP.GetStreetAddr&#40;Lat, Lon, Streets, Direction, Distance&#41;;
    
          if Streets.Count = 0 then begin
             WriteLn&#40;'No match found'&#41;;
             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 &#58;= '';
          for n &#58;= 0 to Streets.Count - 1 do
             if Length&#40;Streets&#91;n&#93;&#41; > Length&#40;Street&#41; then
                Street &#58;= Streets&#91;n&#93;;
    
          WriteLn&#40;'Point is ' + IntToStr&#40;Distance&#41; + ' meter ' + Direction + ' from ' + Street&#41;;
       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

  4. #4
    RobinX is offline 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

  5. #5
    RobinX is offline 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.

  6. #6
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    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.

  7. #7
    RobinX is offline Junior Member White Belt
    Join Date
    Mar 2006
    Posts
    4
    Hello Wilfried !

    Oke, thanks ! Im going to check it out

    Cheers

    Robin

  8. #8
    Srinivas Loka is offline 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

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

  10. #10
    DColeman is offline 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

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Snap to Road Feature duplicated
    By douglashawkins in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 03-23-2005, 01:36 PM
  2. mappoint snap to road
    By Omair in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-25-2004, 07:44 AM
  3. MS Snap files
    By surferj in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 05-28-2003, 03:54 PM
  4. I need to map an off road trail
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 04-20-2003, 10:54 PM
  5. How can I find nearest point on a road from a point off-road
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-12-2002, 07:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85