Display Google map or Bing Map in Windows forms appliction

Topics: SharpMap v0.9 / v1.x, WinForms Controls
May 2, 2014 at 5:45 AM
Hello ;

Is there any way of displaying Google or Bing map in windows forms application . I have a shape file and need to underlay Google or Bing Map so my analysis is much more easier . I've tried some code but had no luck . Any code snippet is much appreciated .
May 2, 2014 at 8:55 AM
This is how you can display an OSM map
            osmTileSource = new TileSource(new WebTileProvider(new BasicRequest("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", new[] { "a", "b", "c" }), new FileCache(@"c:\temp\BruTile\OSM", "png"), null), new GlobalSphericalMercator(0, 18));
var tileLayer = new TileAsyncLayer(osmTileSource,layerName);


Bing and goole are similar. See brutile examples for more info
May 7, 2014 at 1:34 AM
Thanks for the Idea Robert .
I got a code which uses Bing map.
TileAsyncLayer tlAlayer = new TileAsyncLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Hybrid), "TileLayer - Bing");
But it is not displaying a map . It's showing a blank back ground .
May 7, 2014 at 6:04 AM
If you want to use Bing map, you have to provide a valid Bing map api key as second parameter for BingTileSource.
Otherwise you have to use BingRequest.UrlBingStaging.
May 7, 2014 at 6:17 AM
Hello FObermaier;
I do have a Bing API test key and I'm using It . I tried the method you suggested , still the result is same . I tried the google source also
TileLayer googleLayer = new TileAsyncLayer(new GoogleTileSource(new GoogleRequest(GoogleMapType.GoogleMap), new MemoryCache<byte[]>(100, 1000)), "TileLayer - Google");
For both I'm getting blue screens with a "camera forbidden" image .
May 7, 2014 at 7:16 AM
You did zoom to the extent of the layer (Map.ZoomToExtents()), did you?
May 8, 2014 at 12:26 AM
Hello FObermaier;

Please see this code this is what I'm using . I'm not able to find out the mistake . when I use Google I got an Image "CRO 4 WEB" . With Bing ,I'm getting same image.
            SharpMap.Layers.TileLayer tLayer;
            BingTileSource blsource;
            //blsource = new BingTileSource(BingRequest.UrlBing,token, BingMapType.Hybrid);
            blsource = new BingTileSource(BingRequest.UrlBingStaging, "", BingMapType.Hybrid);
            //glsource = new GoogleTileSource(GoogleMapType.GoogleMap);
             //tLayer = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap),"Gl",c,true,Path.GetTempPath());
            //TileAsyncLayer tlAlayer = new TileAsyncLayer(blsource, "TileLayer - Bing");
            //tLayer = new TileLayer(blsource, "TileLayer - Bing", cl1, true, Path.GetTempPath());
             tLayer = new TileLayer(blsource, "");
             tLayer.Enabled = true;
            _mapBg = new Map();
            mapBGMaps.Map = _mapBg;
            mapBGMaps.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
May 8, 2014 at 6:19 AM
As I said, you need to add a call to ZoomToExtents(). If you don't do that, the tile layer will try to get a tile for a zoom level that is not supported.
_mapBG = mapBGMaps.Map;
// You must call either this or _mapBG.ZoomToBox(...); at least once!
// Otherwise I think, your _mapBG.Envelope is set to the initial size of MapBox control.
// ...
May 8, 2014 at 6:30 AM
Thank you Friend ... Now it is showing the map...