1

Trying to load OSM on windows Form using C# and GMap.Net I am getting this error

Exception:The remote server returned an error: (403) Forbidden

    private void Form1_Load(object sender, EventArgs e)
    {

        gMapControl1.DragButton = MouseButtons.Left;
        gMapControl1.CanDragMap = true;
        gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
        gMapControl1.Position = new GMap.NET.PointLatLng(54.6961334816182, 25.2985095977783);
        gMapControl1.MinZoom = 0;
        gMapControl1.MaxZoom = 24;
        gMapControl1.Zoom = 9;
        gMapControl1.AutoScroll = true;


    }

Can you please let me know why this is happening and how I can fix it?

enter image description here

Behseini
  • 6,066
  • 23
  • 78
  • 125
  • 1
    Can you show us the complete HTTP request and response, e.g. using wireshark? Which OSM tile server are you using? Does your program respect the [tile usage policy](https://operations.osmfoundation.org/policies/tiles/), for example does it send a valid referrer? – scai Apr 21 '17 at 06:48
  • To complement scai's comment, usually tile servers (and their stylesheets) don't go above 18-20 zoom level. It should not result in HTTP 403 statuses, but beware of this. – gileri Apr 21 '17 at 09:54
  • @scai, thanks for reply where can I check the Tile server? I mean as I said I am using GMap.Net so how can I check the request or tile usage policy? – Behseini Apr 21 '17 at 20:06
  • Sorry, I don't know. I've never used this framework. – scai Apr 22 '17 at 07:26
  • @Behseini Did you ever solve this? I assume it's some kind of policy issue with OSM (GMap.NET seems to have a lot of those kind of issues). – peeebeee Jan 18 '18 at 08:14
  • This is also an error that occurred suddenly, after years of using the service. Switching to BingProvider fixes the problem, but question is for how long. Is there a way to contat openstreetmap.org and ask them if they blocked? – Ted May 29 '19 at 07:53

3 Answers3

2

don't forget to set the instance mode to server/cache and set it to the instance of the open street map provider instead of 'GMapProviders.OpenStreetMap'

GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache; 
gMapControl1.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;

It could also be your web proxy settings, see https://stackoverflow.com/a/19609539/2368681

Community
  • 1
  • 1
pm101
  • 1,309
  • 10
  • 30
1

"Hi,

All libraries that send a fake user-agent and other faked headers to make the requests appear as if they are coming from web browsers are being blocked. Fix the headers and set a real User-Agent to identify your app and the requests will work again.

Please review our usage policy: https://operations.osmfoundation.org/policies/tiles/ "

This is verbatim reply from OSM.

https://github.com/judero01col/GMap.NET/pull/45 is being used to track this issue. And hopefully a fix will be merged in a a day or two.

prasooncc
  • 11
  • 1
  • 2
1

I changed Map Provider from "OpenStreetMapProvider" to "GoogleMapProvider" and the error disappeared.

GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache; mapView.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;

Jay
  • 11
  • 1