0

I'm trying to download a MapProvider to use offline map but i dont know how to download. it works when i use ServerOnly. This is my code:

GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
        _map = new GMapControl();
        Map.MapProvider = GMap.NET.MapProviders.BingHybridMapProvider.Instance;
        Map.DragButton = MouseButton.Left;
        Map.MinZoom = 2;
        Map.MaxZoom = 18;
        Map.Zoom = 5;
        Map.CanDragMap = true;
        Map.Position = new GMap.NET.PointLatLng(48.8589507, 2.2775175);
        Map.ShowCenter = false;

Thank you everyone

Avi C
  • 13
  • 4

1 Answers1

0

You can cache the map in the local storage using the ServerAndCache found in GMap.NET.AccessMode

The following function will do the work:

private void gMapStoreOffline(int lat, int lng)
{

 gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
 GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
 GMap.NET.MapProviders.OpenStreetMapProvider.UserAgent = "IE";
 
 gMapControl1.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
 GMaps.Instance.OptimizeMapDb(null);

 // Define the location to cache the file
 gMapControl1.CacheLocation = @"C:\Users\<username>\..";
 gMapControl1.Zoom = 14;
 gMapControl1.Size = new Size(this.Width, this.Height);
 gMapControl1.ShowCenter = false;
 gMapControl1.Position = new GMap.NET.PointLatLng(lat, lng)

}
Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24
  • Thank you, it works, but when i use CacheOnly it show me only the areas that i already saw on ServerAndCache mode. There is option to save the whole map to the cache ? – Avi C Jul 30 '22 at 08:38
  • @AviC does [this](https://stackoverflow.com/a/43474499/14291243) answers your question? – Abhishek Dutt Jul 31 '22 at 04:00