problem in showing map

Topics: Bugs, Windows Forms
May 8, 2013 at 9:43 AM
hi
some times in my application the map is not showing and a red cross is showing instead of it
the error cause this problem is here:
Arithmetic operation resulted in an overflow. At    at GMap.NET.Internals.Tile.<get_Overlays>d__0.MoveNext()
   at GMap.NET.WindowsForms.GMapControl.DrawMap(Graphics g)
   at GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
what should i do?
thanks
May 8, 2013 at 9:59 AM
what do you mean 'sometimes'? It never happened to me ;/
May 8, 2013 at 2:05 PM
radioman wrote:
what do you mean 'sometimes'? It never happened to me ;/
maybe it's because of updating markers location
how to update them with background worker and locks?
i don't know i should lock which variable
markers or polygons or the whole overlay ?

thanks
May 8, 2013 at 2:06 PM
check the demo, there are few examples of live data
Jun 23, 2013 at 8:06 PM
i have done just the same as what is on demo application
but sometimes it gives the following exception:
2013/06/23 06:51:11.33 Arithmetic operation resulted in an overflow. At    at GMap.NET.Internals.Tile.<get_Overlays>d__0.MoveNext()
   at GMap.NET.WindowsForms.GMapControl.DrawMap(Graphics g)
   at GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
i update the markers every 20 seconds from database
Jun 24, 2013 at 8:42 AM
does the demo throws the same exception?
Jun 24, 2013 at 9:40 AM
radioman wrote:
does the demo throws the same exception?
no
how can i find out why this is happening?
i have just copied demo's source code into my application and fill my values in the collection
is it because of application setting (optimization,...) or something like that?
Jun 24, 2013 at 10:14 AM
you are doing something wrong ;/
Jun 24, 2013 at 1:58 PM
Edited Jun 24, 2013 at 1:58 PM
radioman wrote:
you are doing something wrong ;/
here is my code:
List<CarData> driversData = new List<CarData>();
SqlDataAdapter DataAdapter = new SqlDataAdapter();

protected void LoadDataOfLastPosition(DoWorkEventArgs e)
{
    lock (driversData)
    {
        driversData.Clear();
        string CommandString = "SELECT  id,lat,lng from LastPosition";

        if (DataAdapter.SelectCommand == null) DataAdapter.SelectCommand = new SqlCommand(CommandString, new SqlConnection(sqlConnectionString));

        if (DataAdapter.SelectCommand.Connection.State == ConnectionState.Closed)   DataAdapter.SelectCommand.Connection.Open();

        DataAdapter.SelectCommand.CommandType = CommandType.Text;
        DataAdapter.SelectCommand.CommandText = CommandString;
        SqlDataReader reader = DataAdapter.SelectCommand.ExecuteReader();
        try
        {
            while (reader.Read())
            {
                if (bwUpdateData.CancellationPending && !preventCancellation)
                {
                    e.Cancel = true;
                    return;
                }
                CarData cardata = new CarData();
                cardata.ID = reader.GetInt32(0);
                cardata.Latitude = reader.GetDouble(1);
                cardata.Longitude = reader.GetDouble(2);
                driversData.Add(cardata);
            }
            reader.Close();
        }
        catch (Exception)
        {
            reader.Close();
        }
    }

}

private void bwUpdateData_DoWork(object sender, DoWorkEventArgs e)
{

    if (bwUpdateData.CancellationPending && !preventCancellation)
    {
        e.Cancel = true;
        return;
    }

    try
    {
        updating = true;                
        bwUpdateData.ReportProgress(15,"fetch from database started");
        LoadDataOfLastPosition(e);
        bwUpdateData.ReportProgress(16,"fetch from database ended"); 
       
        // do other updates on form
       
        bwUpdateData.ReportProgress(100,"update ended");
        updating = false;
    }
    catch (NullReferenceException NREX)
    {

    }
    catch (Exception ex)
    {
        updating = false;
    }
    finally
    {
        Thread.Sleep(20000);
    }
}


private void bwUpdateData_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            try
            {
                if (e.ProgressPercentage == 100)
                {
                    gMapControl1.HoldInvalidation = true;
                    driversCollection.Markers.Clear();

                    lock (driversData)
                    {
                        foreach (CarData item in driversData)
                        {
                            Bitmap bmp = RotateImage(); //rotate marker in a direction of car
                            PointLatLng pos = new PointLatLng(item.Latitude, item.Longitude);
                            GMapMarkerCar m = new GMapMarkerCar(pos, bmp);
                            m.ToolTip = new GMapRoundedToolTip(m);
                            m.ToolTip.Format.Alignment = StringAlignment.Center;
                            m.ToolTip.Format.Trimming = StringTrimming.None;
                            m.ToolTip.Format.FormatFlags = StringFormatFlags.DirectionRightToLeft | StringFormatFlags.NoWrap;
                            m.Tag = item.DriverID;
                            m.ToolTipText = "somevalue";
                            driversCollection.Markers.Add(m);
                            if (item.ID == CurrentSelectedCar)
                                gMapControl1.Position = m.Position;
                        }
                        gMapControl1.Refresh();
                    }
                }

                toolStripProgressBar1.Value = e.ProgressPercentage;
                toolStripProgressBar1.Visible = true;
                toolStripStatusLabelUpdateLevel.Text = (e.UserState != null) ? e.UserState.ToString() : string.Empty;
            }
            catch (Exception)
            {

            }

        }

        private void bwUpdateData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                AddLog("bwUpdateData Cancelled");
            }
            else if (e.Error != null)
            {
                AddLog("Update Finished with result " + ((e.Result != null) ? e.Result : "") + " " + ((e.Error != null) ? e.Error.Message : ""));
            }
            else
            {                
                bwUpdateData.RunWorkerAsync();
            }
        }
Jun 24, 2013 at 2:33 PM
well you clear all markers each time and don't reuse them, but even with that it should work just fine
Jun 24, 2013 at 5:33 PM
radioman wrote:
well you clear all markers each time and don't reuse them, but even with that it should work just fine
as u see i do just the same as demo app
but some times the red cross is appearing on the gmapcontrol
Sep 11, 2013 at 8:46 AM
I put the map controller in windows form. When i run it for the first time, map is perfectly displayed. But when i call it second time big red cross on white back ground is displayed. Can you tell me why?

My Code
Public Shadows Sub ShowDialog(ByVal owner As Form, ByVal LAT As Double, ByVal LON As Double)
    _Lat = LAT
    _Lon = LON
    MyBase.ShowDialog(owner)
End Sub

Private Sub myMap_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles myMap.Disposed
    myMap.Dispose()

End Sub
Private Sub myMap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myMap.Load


    'not use proxy
    GMapProvider.WebProxy = Nothing

    myMap.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance
    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly
    'myMap.SetCurrentPositionByKeywords("CAMDEN, AUSTRALIA")

    myMap.Position = New PointLatLng(_Lon, _Lat)
    Dim markersOverlay As GMapOverlay = New GMapOverlay("markers")
    Dim marker As GMarkerGoogle = New GMarkerGoogle(New PointLatLng(_Lon, _Lat), GMarkerGoogleType.green)
    markersOverlay.Markers.Add(marker)
    myMap.Overlays.Add(markersOverlay)




    myMap.MinZoom = 1
    myMap.MaxZoom = 20
    myMap.Zoom = 12

End Sub
Sep 11, 2013 at 9:27 AM
you cant use disposed map
Sep 11, 2013 at 11:44 AM
is there a way to do it?
Sep 11, 2013 at 12:24 PM
Actually I have a list view with addresses. When user clicks on it, I am calling new form which has a map controller and tried to display that address on it.
For the first time it is working fine. But next time when I close the form and tried to load the address it is not getting displayed?

Your suggestion on this is highly appreciated
Sep 11, 2013 at 12:50 PM
hide/show the form instead
Sep 11, 2013 at 1:29 PM
Can you tell me why I have to hide/show the form? What happens to map controller when I closed the form?
Sep 11, 2013 at 1:39 PM
Even if I hide/show the form instead, I am having the same problem.

Can you guide me on this?
Sep 11, 2013 at 1:46 PM
you can't have the same problem if hide/show it
Sep 11, 2013 at 2:26 PM
why all the markers are getting added. How to replace the existing markers with the new one?