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 3 of 3

displaying the coordinates of mouse when moving

This is a discussion on displaying the coordinates of mouse when moving within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi I'm trying to display the coordinates ( lat,long) of the mouse. On the mouse move event I add: Location ...

  1. #1
    wmoti is offline Junior Member White Belt
    Join Date
    Aug 2006
    Posts
    2

    displaying the coordinates of mouse when moving

    Hi
    I'm trying to display the coordinates ( lat,long) of the mouse.
    On the mouse move event I add:
    Location loc = map.XYToLocation(e.x,e.y);

    loc suppose to have the geogaphic location .
    now I'd like to use it but I dont know how to get it out of 'loc'?

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

    Put this event handler in OnMouseMove:

    Code:
            private void MP_MouseMoveEvent(object sender, AxMapPoint._IMappointCtrlEvents_MouseMoveEvent e)
            {
                AxMapPoint.AxMappointControl mp = (AxMapPoint.AxMappointControl)sender;
                Location loc = mp.ActiveMap.XYToLocation(e.x, e.y);
                if (loc != null) {
                    double lat;
                    double lon;
                    MPTools.calcPos(mp.ActiveMap, loc, out lat, out lon);
                    statusStripLat.Text = lat.ToString("F5");
                    statusStripLon.Text = lon.ToString("F5");
                }
            }
    Then for the calcPos you can make a static class:

    Code:
        public static class MPTools
        {
            private static Map map;
            private static Location locNorthPole;
            private static Location locSantaCruz;
            private static double halfEarth;
            private static double quarterEarth;
    
            /// <summary>
            /// Compute latitude and longitude given a location object
            /// Original Author: Gilles Kohl [ gilles@compuserve.com ]
            /// This code is copyrighted freeware - use freely, but please leave this
            /// header intact. Suggestions and comments welcome.
            /// </summary>
            public static void calcPos(Map activeMap, Location loc, out double lat, out double lon)
            {
                if (map != activeMap) { // First time, or another map loaded.
                    map = activeMap;
                    locNorthPole = map.GetLocation(90, 0, 0);
                    locSantaCruz = map.GetLocation(0, -90, 0);
                    halfEarth = map.Distance(locNorthPole, map.GetLocation(-90, 0, 0));
                    quarterEarth = halfEarth / 2;
                }
                lat = 90 - 180 * map.Distance(locNorthPole, loc) / halfEarth;
                double D = map.Distance(map.GetLocation(lat, 0, 0), loc);
                double L = Deg2Rad(lat);
                lon = 180 * Math.Acos((Math.Cos(D * Math.PI / halfEarth) - Math.Pow(Math.Sin(L), 2)) / Math.Pow(Math.Cos(L), 2)) / Math.PI;
                if (map.Distance(locSantaCruz, loc) < quarterEarth)
                    lon = -lon;
            }

  3. #3
    wmoti is offline Junior Member White Belt
    Join Date
    Aug 2006
    Posts
    2

    Smile Thak You

    p.s : After I wrote this post , I have noticed that many users asked it before , and read their answers . but thanks again .

    Regards,
    Moti

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Moving Text Balloon Issue
    By mroyle in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 10-13-2005, 05:20 PM
  2. moving through recordset is slow
    By stephenmillington in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 07-07-2004, 06:28 AM
  3. Considering Moving To MP2k4
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 05-04-2004, 03:46 PM
  4. Moving pushpin when linking data
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-13-2004, 06:53 PM
  5. moving pushpins
    By joseph in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 02-27-2003, 11:44 PM

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