Interactive Google Maps in C # winform

I have an app with google maps. Maps are currently displayed in WebBrowser using the Javascript Maps API.

I have a requirement that the card interact with the application. In particular, I placed markers on the map. Winform must be registered when one of them is clicked, double-clicked, etc. And found out which one was. If the user right-clicks on an empty area on the map, I need to somehow register how to draw a context menu, and a lat / long pixel representing a geospatial view.

I don't care if the card remains in the webbrowser control or is replaced by something else. If necessary, I can rip it all off and place a new map - but it must be Google (because we have an expensive corporate API), and it absolutely must remain inside winform.

How can I accomplish this interactivity?

+7
c # winforms google-maps
source share
3 answers

The part where you said that you want to replace the web version with something else was almost missing.

See Great Maps - for Windows Forms and WPF . This is a custom WinForms control that you can remove on the form.

It supports many map providers, including Google Maps. They have a demo with which you can play and see how it works and how it can be integrated.

From experience, I can say that you can (quite easily) bind to map events (the marker clicked, double-clicked).

Something worth noting that using Google Maps may violate Google’s terms of use (you will also receive a warning in the demo application). You can always explore some free providers, such as OpenStreetMap.

+9
source share

With GDS Google Map WinForms Control, you can easily do this by responding to MapMarkerMouseCick or MapMarkerMouseDoubleClick events. Here's how:

  • Create a new WinForm application;
  • Drag GdsGoogleMap onto the form, name it as _gdsGoogleMap and set its dock to "Fill";
  • Create two event handlers: GdsGoogleMapMapInitializedEventHandler to initialize the GdsGoogleMapMapMarkerMouseClickEventHandler map to display the Gds mouse marker
  • Enter the following codes:

    using System.Drawing; using System.Windows.Forms; using GdsGoogleMap.DisplaySettings; using GdsGoogleMap.FeatureLayers; using GdsGoogleMap.Features; using GdsGoogleMap.GeoData; using GdsGoogleMap.MapEvents; namespace MarkersMap { public partial class Form1 : Form { private const string RbcLayer = "RBC"; private MarkerLayer _rbcLayer; public Form1() { InitializeComponent(); } private void GdsGoogleMapMapInitializedEventHandler(object sender, MapInitializedEventArgs e) { _gdsGoogleMap.MapCenter = new LatLng( 50.9249106, -114.0325575 ); _gdsGoogleMap.MapZoom = 12; _rbcLayer = ( MarkerLayer ) _gdsGoogleMap.FeatureLayerCollection.Add( RbcLayer, FeatureOptions.Marker ); _rbcLayer.DisplaySettings = new MarkerDisplaySettings { DisplayColor = Color.Orange }; var collection = _rbcLayer.MarkerCollection; collection.Add( new Marker ( MarkerTypeOptions.Text, 50.90408, -114.0656808, "R", "RBC Bank\r\nShawnessy Centre\r\n250 Shawville Blvd SE, Calgary, AB\r\nPhone: (403) 292-2651\r\nTransit #2299" )); collection.Add( new Marker ( MarkerTypeOptions.Default, 50.9011082, -114.1171142, "R", "RBC Bank\r\nBridlewood Shopping Centre\r\n16919 24th St SW, Calgary, AB\r\nPhone: (403) 509-2846\r\nTransit #180" )); collection.Add( new Marker ( MarkerTypeOptions.Empty, 50.8745118, -114.0317351, "R", "RBC Bank\r\nGates Of Walden\r\n151 Walden Gate SE, Calgary, AB\r\nPhone: (403) 292-8243\r\nTransit #1436" )); } private void GdsGoogleMapMapMarkerMouseClickEventHandler( object sender, MapMarkerMouseClickEventArgs e ) { var marker = _rbcLayer.MarkerCollection[ e.MarkerIndex ]; MessageBox.Show("Mouse Click on \r\n" + marker.Description, "Marker Mouse Click"); } } } 

Note that displaying the Mouse Click Event marker takes precedence over the Double Click Click Map Marker event. This means that if you want to respond to a Double Click event, you do not need to create an event handler for the click event.

Compile and run the program, you will see the following screenshot:

Fig 1: Three different style markers

Hover over one marker, you will see screencut as: Fig 2: Show marker description

We click on one marker, you will see screencut as: enter image description here

+4
source share

I would not use Great Maps for window forms and wpf (GMap.Net) because it violates the Google Map Terms of Service by directly accessing Google Map tiles.

You can place it yourself by clicking on this link: https://github.com/mchall/GoogleMapsApi .

Or you can use one free WPF control at: https://archive.codeplex.com/?p=wpfgooglemap .

We use GDS Google Map . It is not free, but affordable. He does what we need.

0
source share

All Articles