3

Basically I want to draw a filled square and add it (and use it) as a marker to Gmap. I tried drawing a square and use it as a bitmap but it asks me for the x y coordinates and I don't know what values to put for that because the marker already uses lat/long. I am trying this but the position of the square is not right.I want to square to appear on the specified lat/long.

Bitmap flag = new Bitmap(50, 50);
gmap.MapProvider = GMap.NET.MapProviders.BingHybridMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
Graphics fg = Graphics.FromImage(flag);
fg.FillRectangle(Brushes.Red, 100, 100, 50, 50);
GMapOverlay markerOverlay = new GMapOverlay(NametextBox.Text);
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528),flag);
markerOverlay.Markers.Add(marker);
gmap.Overlays.Add(markerOverlay);
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Vaibhav Pandya
  • 115
  • 2
  • 10
  • 1
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 11 '15 at 20:19

3 Answers3

3

To draw a filled square you follow following steps:

  1. Right click on project settings.
  2. Go to resources > add resource > new image.
  3. Double click on new created image.
  4. A blank page opens. Draw whatever you like and save it.

For plotting I used the following example:

GMapMarker marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528), new Bitmap(Properties.Resources.image8));
gmap.Overlays.Add(markers);   // overlay added
markers.Markers.Add(marker);

Hope this works for you.

Jarb
  • 45
  • 6
pranjal khanduri
  • 351
  • 1
  • 3
  • 16
0

Using GMap.NET Tutorial – Maps, markers and polygons

The code they provide for custom markers and its assignment to an overlay is the following:

GMapOverlay markersOverlay = new GMapOverlay("markers");
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528), GMarkerGoogleType.green);
markersOverlay.Markers.Add(marker);
gmap.Overlays.Add(markersOverlay);

Hope this helps.

Baz Guvenkaya
  • 1,482
  • 3
  • 17
  • 26
Solorn
  • 101
  • 2
  • 2
  • 6
0

As I understand your question, the issue is not the creation of the bitmap itself, but that the flag does not appear in the correct location. In order to make it appear in the correct location, you will have to modify the Offset property of the Marker object.

Bitmap flag = new Bitmap(50, 50);
gmap.MapProvider = GMap.NET.MapProviders.BingHybridMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
Graphics fg = Graphics.FromImage(flag);
fg.FillRectangle(Brushes.Red, 100, 100, 50, 50);
GMapOverlay markerOverlay = new GMapOverlay(NametextBox.Text);
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528),flag);
marker.Offset = new Point(-flag.Width/2, -flag.Height/2);  // Set point to middle of bitmap
markerOverlay.Markers.Add(marker);
gmap.Overlays.Add(markerOverlay);
MrWuf
  • 1,478
  • 1
  • 14
  • 30