judero01col / GMap.NET

GMap.NET Windows Forms & Presentation is an excellent open source, powerful, free and cross-platform .NET control. Allows the use of routing, geocoding, directions and maps from Google, Yahoo!, Bing, OpenStreetMap, ArcGIS, Pergo, SigPac, Yendux, Mapy.cz, Maps.lt, iKarte.lv, NearMap, HereMap, CloudMade, WikiMapia, MapQuest and many more.
Other
458 stars 201 forks source link

SetPositionByKeywords doesn't work anymore #209

Open Triskh opened 3 months ago

Triskh commented 3 months ago

I have an programm that set's the map position with keywords, but since a few days this doesn't work anymore. The map itself works normaly and the position can be set with coordinates. As mapprovider i use openstreetmap.

Has anyone the same problem or has anyone an idea to fix this problem?

salbertsCAD commented 3 months ago

I don't think we use this particular method, but we do use the GetPositionByKeywords method. And I think we're having the same problem. Debugging session shows that a web request to get the location information from the keywords, returns a 403 Forbidden. Hopefully this will be fixed soon!

jonas-medCrew commented 3 months ago

Same here on GetPositionByKeywords using OpenStreetMap. Does anyone know a workaround?

jonas-medCrew commented 3 months ago

Error seems to appear on request to hhtps://nominatim.openstreetmap.org/search... I Fixed it by doing the request myself in helperclass to get the coordinates of an address or searchstring.

Solution looks like this: `private static HttpClient _client;

static MapHelper() { _client = new HttpClient() { BaseAddress = new Uri("https://nominatim.openstreetmap.org/"), }; _client.DefaultRequestHeaders.Add("User-Agent", ""); }

public static async Task GetPointFromUrl(string keys) { try { string text = await _client.GetStringAsync($"search?q={keys.Replace(" ", "+")}&format=json"); var list = JsonConvert.DeserializeObject<List>(text); if (list?.Count > 0) { return new PointLatLng(list.First().lat, list.First().lon); } } catch (Exception ex) { Debug.WriteLine($"Error: {ex.Message}"); } return default; } `

Without setting UserAgent header the request will result in 403 forbidden.

Hope it helps.

A Fix of this issue would be really nice anyways

salbertsCAD commented 3 months ago

Can confirm jonas' solution worked for us too. Thank you for sharing your solution! Shame it has to come to manual workarounds, hopefully they will fix it on their side soon.