Use Google Maps with Brutile

Mar 10, 2011 at 2:33 PM

Hi

I tried the Silverlight.Mapsui sample and it works with OSM maps.

Now I tried to use Google maps:

- in GUIOverlay.xaml I have the following code:

 private Map CreateMap()
        {
            var map = new Map();
            var googleLayer = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleSatellite)) { LayerName = "Google" };
            map.Layers.Add(googleLayer);
            var pointProvider = new MemoryProvider(GenerateRandomPoints(osmLayer.Envelope));
            map.Layers.Add( new Layer("Points") { DataSource = pointProvider });
            return map;
        }

in GoogleTileSource.cs I have this code:

 public class GoogleTileSource : ITileSource
    {
        private readonly SphericalMercatorInvertedWorldSchema _tileSchema;
        private readonly WebTileProvider _tileProvider;
        public const string UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11";
        private const string Referer = "http://maps.google.com/";

        public GoogleTileSource(GoogleMapType mapType)
            : this(new GoogleRequest(mapType), new NullCache())
        {
        }
        public GoogleTileSource(GoogleRequest request)
            : this(request, new NullCache())
        {
        }
       
        public GoogleTileSource(GoogleRequest request, ITileCache<byte[]> fileCache)
        {
            _tileSchema = new SphericalMercatorInvertedWorldSchema();
            _tileProvider = new WebTileProvider(request, fileCache, UserAgent, Referer, true);
        }

 

Now I get a securityecxeption. I think it could be the clientaccess/crossdomain.xml problem with SL4.

I didn't find a solution. Does anybody have an idea how to solve that? Is it not necessary to have a valid Google Map Key?

The second problem is, that the point provider in the sample code doesn't show any points. Does anybody know about this problem?

 

Cheers stefan

Coordinator
Mar 11, 2011 at 4:16 PM
Edited Apr 23, 2011 at 8:19 AM

I have never got Google to work in Silverlight, since my method depends on faking the user agent which is nog possible in SL. 

One thing I havent looked at is the difference between ClientHttp and BrowserHttp. Perhaps with BrowserHttp there will be a different user agent.

http://msdn.microsoft.com/en-us/library/dd920295(v=vs.95).aspx

Although the referer will still be problem I guess. Wonder how that works in the Google flash api: 

http://code.google.com/apis/maps/documentation/flash/

I won't have time to look at it myself, be happy hear if you learned anything.

BTW, I assume the Google Maps license probably doesnt allow this without any special agreements.

cheers,

Paul

Mar 17, 2011 at 12:45 PM

Hi Paul

thank you for the information.

It's a pity that this is not easy to realize. I think I gonna keep my fingers off.

So I try to go ahead with my sharpmap/brutile solution with my own data.

But it's pretty hard as my knowledge isn't that big to create the tile services.

cheers stefan

Apr 21, 2011 at 11:41 AM

the issue is that tile urls use some additional parameters, and they change versions pretty often, need add some auto-detection function

Coordinator
Apr 23, 2011 at 8:26 AM

hi radioman! Good to see you here. 

Could this explain why it does work in WPF but not in Silverlight? The Google Maps code that is now in BruTile is actually based on your GMaps code:

http://brutile.codeplex.com/SourceControl/changeset/view/1887ca9e93d0#BruTile%2fWeb%2fGoogleRequest.cs

Paul

Apr 25, 2011 at 9:12 AM

#if !SILVERLIGHT
static GoogleRequest()
{
   TryCorrectGoogleVersions();
}
#endif

// just update old versions or enable this somehow to work in sl too