C # show gps location on map

I work in a Windows mobile application and I want to show my current location using Google maps. I used the dll Location from the samples. As you see below in my code, I call the correct method to update the map in the gps_Locationchanged event , where I use the Invoke method to update the image with the image. The problem is that I can’t use the main menu and the context menu of the application when I want. It is like they freeze until the new card finishes loading. Is there any other way to do this in different threads so that they can be used at any time?

void gps_LocationChanged(object sender, LocationChangedEventArgs args)
{
    if (args.Position.LatitudeValid && args.Position.LongitudeValid)
    {

       pictureBox1.Invoke((UpdateMap)delegate()
         {
             center.Latitude = args.Position.Latitude;
             center.Longitude = args.Position.Longitude;
             LatLongToPixel(center);
             image_request2(args.Position.Latitude, args.Position.Longitude);

         });
    }
}
+3
source share
2

, - ?

    bool m_fetching;

    void gps_LocationChanged(object sender, LocationChangedEventArgs args)
    {
        if (m_fetching) return;

        if (args.Position.LatitudeValid && args.Position.LongitudeValid)
        {
            ThreadPool.QueueUserWorkItem(UpdateProc, args);
        }
    }

    private void UpdateProc(object state)
    {
        m_fetching = true;

        LocationChangedEventArgs args = (LocationChangedEventArgs)state;
        try
        {
            // do this async
            var image = image_request2(args.Position.Latitude, args.Position.Longitude);

            // now that we have the image, do a synchronous call in the UI
            pictureBox1.Invoke((UpdateMap)delegate()
            {
                center.Latitude = args.Position.Latitude;
                center.Longitude = args.Position.Longitude;
                LatLongToPixel(center);
                image;
            });
        }
        finally
        {
            m_fetching = false;
        }
    }
+3

, , image_request2(), ( ), , . , , .

+3

Source: https://habr.com/ru/post/1752376/


All Articles