How to get location info from my Gmap.NET?

10,110

The error "The name 'GMapProviders' does not exist in the current context" means that it does not recognize "GMapProviders". Make sure that you have added references to GMap to your project. You can do this by right-clicking on the References folder under your project and selecting "Add Reference..." Then browse to the location of "GMap.NET.Core.dll" and "Gmap.NET.Windows.Forms.dll" and add them. For additional reading the MSDN documentation on how to add a reference is located here. You also must make sure that you have a using statement at the top of your .cs file.

using GMap.NET.MapProviders;

Here are some other using statements for GMAP that you may need for other parts of your code:

using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.WindowsForms.ToolTips;
Share:
10,110
Ibrahim
Author by

Ibrahim

Updated on June 04, 2022

Comments

  • Ibrahim
    Ibrahim almost 2 years

    I'm trying to get address info when I click somewhere on my gmap.NET like country, city, address... etc. I have searched enough but the only solution that I have found is here Location information where mouse click on the map GMap.net. The code that I'm using is:

        private void Form1_Load(object sender, EventArgs e)
            {
                // Initialize map:
                gmap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
                GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
                gmap.Position = new PointLatLng(37.9667, 23.7167);
    
                gmap.MouseClick += new MouseEventHandler(map_MouseClick);
    
    
            }
    
    private void map_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                double lat = 0.0;
                double lng= 0.0;
                if (e.Button == MouseButtons.Left)
                {
                    lat = gmap.FromLocalToLatLng(e.X, e.Y).Lat;
                    lng = gmap.FromLocalToLatLng(e.X, e.Y).Lng;
                    //ajout des overlay
                    overlayOne = new GMapOverlay(gmap, "OverlayOne");
                    //ajout de Markers
                    overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(lat, lng)));
                    //ajout de overlay à la map
                    gmap.Overlays.Add(overlayOne);
                    List<Placemark> plc = null;
                    var st = GMapProviders.GoogleMap.GetPlacemarks(new PointLatLng(54.6961334816182, 25.2985095977782), out plc);
                    if (st == GeoCoderStatusCode.G_GEO_SUCCESS && plc != null)
                    {
                        foreach (var pl in plc)
                        {
                            if (!string.IsNullOrEmpty(pl.PostalCodeNumber))
                            {
                                Debug.WriteLine("Accuracy: " + pl.Accuracy + ", " + pl.Address + ", PostalCodeNumber: " + pl.PostalCodeNumber);
                            }
                        }
                    }
                }
    
            }
    

    The error that appeared is The name 'GMapProviders' does not exist in the current context

    I'm trying to understand the code but I can't. I'm beginner programmer with c# and when I try to copy/paste the code into my code there is an error in GMapProviders that is in the map_MouseClick method. There is any one can help me or can enplane the code to me. Thanx.