Map not displaying, DockStyle.Fill

Topics: Windows Forms
Sep 18, 2011 at 5:47 PM

Hi there

 

I am new to this. I am trying to display a map in a c# winform application using the following code

 

        private void Form1_Load(object sender, EventArgs e)
        {
            GMapControl g = new GMapControl();
            
            g.Dock = DockStyle.Fill;
          
            g.MapType = MapType.BingMap;
            g.MaxZoom = 10;
            g.MinZoom = 1;
            g.Position = new PointLatLng(51.31835, 0.873866);
            pnlMap.Controls.Add(g);
            g.Show();
        }
It loads the control but there is no map inside, any ideas what i am doing wrong? Thanks

Coordinator
Sep 18, 2011 at 5:52 PM

use form constructor instead of load event, and 1.5.5.5 version is quite old, some bugs were fixed due docking...

Sep 18, 2011 at 6:02 PM

it makes no difference putting it in to the constructor as the map still doesnt display

Coordinator
Sep 18, 2011 at 6:06 PM

so as i guessed, thats the bug present in last release, use hot build

Sep 18, 2011 at 6:26 PM
Edited Sep 18, 2011 at 6:30 PM

whats that?

 

edit: ok i downloaded that version, am now using the new dll's

 

this is the code i am using to display 

 

        private void Form1_Load(object sender, EventArgs e)
        {
            GMapControl g = new GMapControl();
            
            g.Dock = DockStyle.Fill;
          
            
            g.MaxZoom = 10;
            g.MinZoom = 1;
            g.Position = new PointLatLng(51.31835, 0.873866);
            pnlMap.Controls.Add(g);
            g.Show();
        }
but still no joy

Coordinator
Sep 18, 2011 at 6:34 PM

you still use load event ;}

Sep 18, 2011 at 6:38 PM
radioman wrote:

you still use load event ;}

yeh, even when i move it to the constructor it makes no difference :/

Coordinator
Sep 18, 2011 at 6:46 PM

yes, it does

Sep 18, 2011 at 6:48 PM
Edited Sep 18, 2011 at 6:53 PM

 

        public Form1()
        {
            InitializeComponent();


            GMapControl g = new GMapControl();
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
            g.Dock = DockStyle.Fill;
            g.MaxZoom = 10;
            g.MinZoom = 1;
            g.Position = new PointLatLng(51.31835, 0.873866);
            pnlMap.Controls.Add(g);
            g.Show();

            loadXmlFile();
        }

still no map displayed so how does it make a difference

can i send you my win form app?
Coordinator
Sep 18, 2011 at 7:13 PM
Edited Sep 18, 2011 at 7:15 PM

works perfect:

      public Form1()
      {
         InitializeComponent();

         SuspendLayout();  
         GMapControl MainMap = new GMapControl();
         {
            MainMap.MapProvider = GMapProviders.YahooMap;
            MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
            MainMap.MinZoom = 1;
            MainMap.MaxZoom = 17;
            MainMap.Zoom = 9;
            MainMap.Dock = DockStyle.Fill;
         }
         Controls.Add(MainMap); 
         ResumeLayout(false);
      }
.
Sep 18, 2011 at 7:16 PM
Edited Sep 18, 2011 at 7:18 PM
radioman wrote:

works perfect:

      public Form1()
      {
         InitializeComponent();

         SuspendLayout();  
         GMapControl MainMap = new GMapControl();
         {
            MainMap.MapProvider = GMapProviders.YahooMap;
            MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
            MainMap.MinZoom = 1;
            MainMap.MaxZoom = 17;
            MainMap.Zoom = 9;
            MainMap.Dock = DockStyle.Fill;
         }
         Controls.Add(MainMap); 
         ResumeLayout(true);
      }
.

you sir are a legend :D - thanks so much! - how do you place a marker on the map or is that not possible?

Coordinator
Sep 18, 2011 at 7:18 PM
Edited Sep 18, 2011 at 7:19 PM

cheers! ..anyway using form designer would be easier "_^

p.s. check demo source, it implements all basic functions

Sep 18, 2011 at 7:20 PM
Edited Sep 18, 2011 at 7:21 PM
radioman wrote:

cheers! ..anyway using form designer would be easier "_^

p.s. check demo source, it implements all basic functions

i did have a look for that, where can i find the demo source? was the demo bundled with the libraries i downloaded

 

also, i have to do it programatically as i cant see the drag and drop item in the toolbox

Coordinator
Sep 18, 2011 at 7:21 PM
Edited Sep 18, 2011 at 7:51 PM

http://greatmaps.codeplex.com/SourceControl/list/changesets

p.s. to have control in your toolbox, just drag GMap.NET.WindowsForms.dll on top of it