Location information where mouse click on the map GMap.net
Asked Answered
E

2

8

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

Especially answered 7/2, 2013 at 11:32 Comment(2)
I haven't looked at the API, but is there not a method that you pass the lat long into to get the location, such as gm1.GetLocation(lat, lng);Sebrinasebum
I've searched again thoroughly, but did not find any method like that one or similar to that one that return something like country or city etc.Especially
G
6

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);
                }
            }
        }
    }
Grossularite answered 3/4, 2014 at 2:13 Comment(0)
B
0

while using GMap.Net Libraries, coordinates are used for specific location using latitute and longitute. As question, even place name can be used to locate the position.

            GMapControl.MapProvider = MapProviders.GoogleTerrainMapProvider.Instance
            

            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache
            With Me.GMapControl
                .Position = New GMap.NET.PointLatLng(latitute, longitute)
                .SetPositionByKeywords("Nepal")
                .Zoom = mp_zomlvl
                .ShowCenter = False
            End With
            GMapControl.Refresh()

Remove code: .Position = New GMap.NET.PointLatLng(latitute, longitute) for using .SetPositionByKeywords("Nepal")

Bayly answered 28/9, 2021 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.