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
Results 1 to 5 of 5

Lat/Long in MapPoint and Delphi

This is a discussion on Lat/Long in MapPoint and Delphi within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, i am using the MapPoint ActiveX control in Delphi 7 and i just cannot get the Lat/Long of the ...

  1. #1
    pepumarius is offline Junior Member White Belt
    Join Date
    Apr 2007
    Posts
    5

    Lat/Long in MapPoint and Delphi

    Hi,

    i am using the MapPoint ActiveX control in Delphi 7 and i just cannot get the Lat/Long of the mouse position on map...

    I tried (succesfully) to get the Lat/Long of a specific Location object, but i need something to convert the graphic XY coordinates of the mouse to Lat/Long coordinates. I also tried the function XYToLocation(X,Y: integer), but that doesn't seem to work because it never returns a valid location...

    I want the lat/long coordinates so i can programmatically add a pushpin where the user clicks the map. Maybe there is an easier solution for this? Any idea would be helpful!

    Marius.

  2. #2
    nigel is offline Junior Member White Belt
    Join Date
    Jul 2006
    Posts
    5

    Re: Lat/Long in MapPoint and Delphi

    Global var
    MouseX : Real ;
    MouseY : Real ;







    type
    TLatLong = record
    Lat : Double;
    Long: Double;
    End;


    Function GetLatLong(M: TMapPointControl; Loc: Location): TLatLong;
    var
    LocNorthPole : Location;
    LocSantaCruz : Location;
    DblHalfEarth : Double;
    DblQuarterEarth : Double;
    DblLat : Double;
    DblLon : Double;
    L, D : Double;
    Begin
    LocNorthPole := M.ActiveMap.GetLocation(90, 0, 0);
    LocSantaCruz := M.ActiveMap.GetLocation(0, -90 , 0);
    DblHalfEarth := M.ActiveMap.Distance(locNorthPole, M.ActiveMap.GetLocation(-90, 0, 0));
    DblQuarterEarth := dblHalfEarth / 2;
    DblLat := 90 - 180 * M.ActiveMap.Distance(LocNorthPole, loc) / DblHalfEarth;
    D := M.ActiveMap.Distance(M.ActiveMap.GetLocation(DblLa t, 0, 0), Loc);
    L := (DblLat / 180) * Pi;
    DblLon := 180 * Arccos((Cos((d * 2 * Pi) / (2 * DblHalfEarth)) - Sin(l) * Sin(l)) / (Cos(l) * Cos(l))) / Pi;
    If M.ActiveMap.Distance(LocSantaCruz, Loc) < DblQuarterEarth Then DblLon := - DblLon;
    Result.Long := DblLon ;
    Result.Lat := DblLat ;
    End;






    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    Var
    MyLococation: Location;
    begin

    MyLococation := Map.ActiveMap.XYToLocation(X, Y);
    MouseX := GetLatLong(Map, Loc).Lat ;
    MouseY := GetLatLong(Map, Loc).Long ;


    This should fill MouseX and mouseY with the lat and long of the mouse pointer.

    This could be used in form mousedown or form mousemove, This works ok for me, please let me know if you need more details

    Nigel

  3. #3
    pepumarius is offline Junior Member White Belt
    Join Date
    Apr 2007
    Posts
    5

    Re: Lat/Long in MapPoint and Delphi

    Yes, thanks very much... this works great. Actually, i used the same function, but it seems that i passed it on the simple Map component and not ActiveMap. By doing so, i never go a valid location on map (don't know why).

    Nevertheless, thanks a lot Nigel!

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Lat/Long in MapPoint and Delphi

    the activeX control in delphi 7 ? I was pretty sure it was not working ... unsupported interface or something... So I used the object interface..

  5. #5
    pepumarius is offline Junior Member White Belt
    Join Date
    Apr 2007
    Posts
    5

    Re: Lat/Long in MapPoint and Delphi

    Well, that is an old problem that can be solved by just doing some modifications in the MapPoint_TLB file... After that you have working components!

    Marius.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using MapPoint In Delphi
    By Anonymous in forum MP2K Magazine Articles
    Replies: 8
    Last Post: 12-05-2005, 10:51 AM
  2. MapPoint 2004 and Delphi 5
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 6
    Last Post: 01-20-2005, 07:34 AM
  3. Mappoint addin with Delphi 6
    By jeanluc in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 09-15-2003, 03:03 PM
  4. MapPoint.Application in Delphi
    By joesebi in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-11-2003, 06:16 AM
  5. Mappoint With Delphi 5
    By stuarth in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-08-2003, 11:21 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 86 87 88 89 90 91 92 93 94 95 96