2

当我单击 gmap.NET 上的某个位置(例如国家、城市、地址...等)时,我试图获取地址信息。我已经进行了足够的搜索,但我找到的唯一解决方案是在这里鼠标单击地图的位置信息地图网。我正在使用的代码是:

    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 name 'GMapProviders' does not exist in the current context

我试图理解代码,但我不能。我是使用 c# 的初学者程序员,当我尝试将代码复制/粘贴到我的代码中时,map_MouseClick 方法中的 GMapProviders 中出现错误。有任何人可以帮助我或可以将代码发送给我。谢谢。

4

1 回答 1

1

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;
于 2014-08-25T16:13:22.027 回答