Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location information where mouse click on the map GMap.net

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 get the coordinates i.e (Latitude and Longitude) where my mouse click (left click).

 private void gm1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            double lat = gm1.FromLocalToLatLng(e.X, e.Y).Lat;
            double lng = gm1.FromLocalToLatLng(e.X, e.Y).Lng;
        }
    }

I did not find a way to get the location of that place i.e Country Name, city name etc.

I've searched the forum of Google maps but i did not find this issue answered.

Any

like image 344
Zeeshan Ajmal Avatar asked Feb 07 '13 11:02

Zeeshan Ajmal


People also ask

What is GMap net?

GMap.NET is a powerful, free, cross platform, Open Source . NET control. It enables the use of routing, geocoding, and maps from Google, Yahoo!, OpenStreet in Windows Forms and Presentation, and supports caching! Download demos from CodePlex.


1 Answers

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);
                }
            }
        }
    }
like image 62
Davidi Avatar answered Oct 29 '22 02:10

Davidi