Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ive got a problem in gmap search using name of city. #21

Closed
ppaulerrol opened this issue Oct 18, 2018 · 14 comments
Closed

ive got a problem in gmap search using name of city. #21

ppaulerrol opened this issue Oct 18, 2018 · 14 comments

Comments

@ppaulerrol
Copy link

No description provided.

@cronky78
Copy link

G'day ppaulerrol,

I had the same problem & have come up with a workaround, see below.

Instead of using the inbuilt GMapControl.SetPositionByKeywords() function, I wrote my own local version of based on almost the same code. Seems to work now, but is a bit slower than it was before. I'm not 100% sure why this works but it seems to !

Hope this helps ? Cheers :) Simon

public bool SetPositionByKeywords(string searchWord)
        {
            GeocodingProvider gp = GMap.NET.MapProviders.GMapProviders.OpenStreetMap as GeocodingProvider;

            if (gp != null)
            {
                GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;

                Cursor.Current = Cursors.WaitCursor;
                var pt = gp.GetPoint(searchWord, out status);
                Cursor.Current = Cursors.Default;

                if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue)
                {
                    this.gMapControl1.Position = pt.Value;

                    return true;
                }
                else
                {
                    // error
                    MessageBox.Show("Could not find \"" + searchWord + "\"");
                    return false;
                }
            }
            else
            {
                MessageBox.Show("Could not find \"" + searchWord + "\"");
                return false;
            }
        }

@ppaulerrol
Copy link
Author

thank you bro! i used your code but it is just like the same.. i can't locate the places id like to see in gmap.net. is it a bug or an update error?.

@cronky78
Copy link

Hmm that's strange, it works just fine for me. The trick is in forcing the GeocodingProvider
to be of type 'GMap.NET.MapProviders.GMapProviders.OpenStreetMap' instead of what you were using before (probably Google). Seems to me that Google have changed something their end recently. But by using OpenStreetMap specifically I am able to search again and it's working. Wonder if anyone else can try it too ?

@judero01col
Copy link
Owner

judero01col commented Oct 31, 2018

Greetings, perform the test with the library method using Google Map Map Provider and OpenStreetMap and work without problems. It could indicate how you were using it and what provider, if you are using the sources or the nuget and if you are using an apikey. I leave an example as I am using it.

GeoCoderStatusCode status = MainMap.SetPositionByKeywords(textBoxGeo.Text);

            if (status != GeoCoderStatusCode.G_GEO_SUCCESS)
            {
                MessageBox.Show("Geocoder can't find: '" + textBoxGeo.Text + "', reason: " + status.ToString(), "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

@ppaulerrol
Copy link
Author

i think somethings wrong with Google map provider because when i use OpenStreetMap it works..

@ppaulerrol
Copy link
Author

try using any map provider and it will work. but not google map.

@judero01col
Copy link
Owner

Are you using a valid api key?

@judero01col judero01col reopened this Nov 14, 2018
@ppaulerrol
Copy link
Author

valid api key? i dont understand.

@Maesetsure
Copy link

I have the same problem. With Google don't work but with other providers works fine.

@prkrmx
Copy link

prkrmx commented Mar 28, 2019

for some reason it stopped working also with BingHybridMap
GeoCoderStatusCode returns ExeptionInCode

@MartinStokelj
Copy link

Was there any update on this problem? I made work around with OpenStreetMap but now even this do not work anymore...

    public GeoCoderStatusCode SetPositionByKeywords(string keys)
    {
        GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;
        GeocodingProvider gp = MapProvider as GeocodingProvider;
        if (gp == null)
        {
            gp = GMapProviders.OpenStreetMap as GeocodingProvider;
        }

        if (gp != null)
        {
            var pt = gp.GetPoint(keys, out status);
            if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue)
            {
                Position = pt.Value;
            }
            else
            {
                gp = GMapProviders.OpenStreetMap as GeocodingProvider;
                pt = gp.GetPoint(keys, out status);
                if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue)
                {
                    Position = pt.Value;
                }
            }
        }

        if (status != GeoCoderStatusCode.G_GEO_SUCCESS && !gp.GetType().ToString().Contains("Google"))
        {
            var pt = GMapProviders.GoogleMap.GetPoint(keys, out status);
            if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue)
            {
                Position = pt.Value;
            }
        }

        return status;
    }

@MartinStokelj
Copy link

Never mind i had to update also code for class OpenStreetMapProviderBase, after that it started to work.

@judero01col
Copy link
Owner

judero01col commented Aug 27, 2019

I proceed with the closing of the issues, review issues #51

@Saipula
Copy link

Saipula commented Jun 7, 2023

G'day ppaulerrol,

I had the same problem & have come up with a workaround, see below.

Instead of using the inbuilt GMapControl.SetPositionByKeywords() function, I wrote my own local version of based on almost the same code. Seems to work now, but is a bit slower than it was before. I'm not 100% sure why this works but it seems to !

Hope this helps ? Cheers :) Simon

public bool SetPositionByKeywords(string searchWord)
        {
            GeocodingProvider gp = GMap.NET.MapProviders.GMapProviders.OpenStreetMap as GeocodingProvider;

            if (gp != null)
            {
                GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;

                Cursor.Current = Cursors.WaitCursor;
                var pt = gp.GetPoint(searchWord, out status);
                Cursor.Current = Cursors.Default;

                if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue)
                {
                    this.gMapControl1.Position = pt.Value;

                    return true;
                }
                else
                {
                    // error
                    MessageBox.Show("Could not find \"" + searchWord + "\"");
                    return false;
                }
            }
            else
            {
                MessageBox.Show("Could not find \"" + searchWord + "\"");
                return false;
            }
        }

Thanks a lot! I wrote the same function myself, but for some reason it did not work for me. But yours is working <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants