Location information where mouse click on the map GMap.net

前端 未结 1 1608
广开言路
广开言路 2021-01-12 04:11

I\'m working on Win Forms application along with GMap.net(a library that enables us to use Google Maps in Win Forms Application). Coming straight to the point, I be able to

相关标签:
1条回答
  • 2021-01-12 04:42

    This will give you a list of the named places on the position you click on the map.

       private void map_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                double lat = map.FromLocalToLatLng(e.X, e.Y).Lat;
                double lng = map.FromLocalToLatLng(e.X, e.Y).Lng;
            }
    
            List<Placemark> plc = null;
            var st = GMapProviders.GoogleMap.GetPlacemarks(map.FromLocalToLatLng(e.X, e.Y), 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);
                    }
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题