Reputation: 125
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);
Upvotes: 4
Views: 6361
Reputation: 371
To draw a filled square you follow following steps:
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.
Upvotes: 3
Reputation: 1498
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);
Upvotes: 0
Reputation: 101
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.
Upvotes: 0