Display Google Maps Imagery using Bing Maps Silverlight Control

14. June 2010

I’ve gotten a couple emails asking how to show Google Maps imagery using the Bing Maps Silverlight Control. I previously post how to display OpenStreetMaps and Yahoo maps imagery using the control, but is it possible to show Google Maps imagery too?? Yes, absolutely; well technically, but the Google Maps Terms of Use does prohibit it. Actually, the Google Maps Terms of Use prohibits the direct access of the map tile images, and does not specifically prohibit using them with the Bing Maps Silverlight Control.

SLBingMapsControl_GoogleMapsImagery

You may only continue reading if you are willing to break the Google Maps Terms of Use, and see how similar the two mapping platforms really are.

Remember the below code most likely violates the Google Maps Terms of Use, and probably shouldn’t be used in a production system; unless of course you really don’t mind breaking the terms of use.

The below code follows suite after the code I posted a while back on displaying OpenStreetMap and Yahoo Maps imagery within the Bing Maps Silverlight Control.

First, here’s some XAML usage samples using the Google Maps TIle Source classes listed further down. The first one is showing the Google Maps Road/Terrain imagery, the second shows the Google Maps Aerial/Satellite imagery:

<!-- Display Google Maps Road/Terrain Imagery -->
<m:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed">
<m:Map.Mode>
<!-- Do Not Display Bing Maps Imagery -->
<mCore:MercatorMode></mCore:MercatorMode>
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<local:GoogleMapsRoadTileSource></local:GoogleMapsRoadTileSource>
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>

<!-- Display Google Maps Aerial/Satellite Imagery with Labels -->
<m:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed">
<m:Map.Mode>
<!-- Do Not Display Bing Maps Imagery -->
<mCore:MercatorMode></mCore:MercatorMode>
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<local:GoogleMapsAerialTileSource></local:GoogleMapsAerialTileSource>
<local:GoogleMapsLabelsTileSource></local:GoogleMapsLabelsTileSource>
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>

 

If you notice, the second example showing the usage of the Google Maps Aerial/Satellite imagery is displaying 2 tile sources. This is because Google Maps has separate tile sources for both the Aerial/Satellite imagery and the Labels. This example shows the Labels tile source over the top of the Aerial/Satellite tile source to give the desired effect of “Aerial with Labels.”

Now, here’s the main attraction of this article; the actual Google Maps TileSource objects referred to above:

public class GoogleMapsRoadTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsRoadTileSource()
: base("http://mt{0}.google.com/vt/lyrs=m@128&hl=en&x={1}&y={2}&z={3}&s=")
{ }
}

public class GoogleMapsAerialTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsAerialTileSource()
: base("http://khm{0}.google.com/kh/v=62&x={1}&y={2}&z={3}&s=")
{ }
}

public class GoogleMapsLabelsTileSource : GoogleMapsTileSourceBase
{
public GoogleMapsLabelsTileSource()
: base("http://mt{0}.google.com/vt/lyrs=h@128&hl=en&x={1}&y={2}&z={3}&s=")
{ }
}

public abstract class GoogleMapsTileSourceBase : Microsoft.Maps.MapControl.TileSource
{
public GoogleMapsTileSourceBase(string uriFormat)
: base(uriFormat)
{ }

public override System.Uri GetUri(int x, int y, int zoomLevel)
{
return new Uri(string.Format(this.UriFormat, new Random().Next() % 4, x, y, zoomLevel));
}
}

 

Disclaimer: Use the above posted code at your own risk. The usage of it may be in violation of the Google Maps Terms of Use.

Bing Maps, Silverlight , ,

Comments

6/18/2010 10:40:53 AM #
Found your site on yahoo today and really liked it.. I bookmarked it and will be back to check it out some more later.
6/18/2010 12:33:24 PM #
Hurray! A decent blog at last which gives the information I desperately need. Fantabulosy! Thank you so much.
6/18/2010 12:34:42 PM #
great post, thanks for sharing.
6/18/2010 2:24:29 PM #
hey, weren't you the one who posted something similar to this on another website before? Just thinking because I remember I seen this piece of information on another weblog while using blog searching in google.
6/18/2010 9:23:36 PM #
Hey very good blog!!!! Wow... Gorgeous .. Amazing .. I’ll bookmark your weblog and take the feeds also...
6/19/2010 6:23:03 PM #
I've been looking for a similar to this post. Not only extensively but also detailly. We can learn a lot from the post. I recommend to you , you can come communication in here. Let us grow up together.On the other hand ,I know some websites content is very well.you can go and see.Such as www.freees.net
6/20/2010 2:30:36 AM #
Nice post, thanks.
6/20/2010 7:25:57 AM #
I had a website like this once, but I got so much spam I had to shut it. You appear to be better at weeding out the spam! Congratulations!
6/20/2010 10:49:38 AM #
I was very pleased to find this site.I wanted to thank you for this awesome read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out new stuff you post.
6/20/2010 4:35:14 PM #
as I have already seen that there is commenting going on in large number...so I indicate that how your blog popular is?
6/20/2010 5:22:00 PM #
Just in case you didn't know... your web site looks very peculiar in Mozilla on a Mac
6/20/2010 5:56:43 PM #
This post has helped myself to understand my want. It has great details that are easy to understand. It also has good tips.
6/20/2010 6:57:07 PM #
Great article it's quite useful, i have just started my own website and it looks like this will help me a lot! Do you have any tips for me? ~ <A href="www.webmastershelpguide.com/.../A>
6/20/2010 7:37:51 PM #
Great post, nice job. It Couldn't be written any better. Reading this post reminds me of my previous room mate! He constantly kept babbling about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for posting!