Previously, when I used the map control in Windows Phone, I always loaded Bing map in English and thought that I had to wait for MS to provide a Chinese map; at the same time, Google and Baidu did not find the corresponding map SDK or API. That's annoying. Bing map in English is so painful; during this period, I saw some ways to load a Google Map or bing map using titlesource. However, these methods are informal methods, so I am worried that problems will occur after the application is released. Later I got a message from Nokia, nokia will provide a formal Windows Phone map, but it needs to go through a commercial contract ......, I only sorted out how to load the Chinese bingmap and Google map methods; source code
The general idea of implementation is to rewrite titlesource, add a layer in bingmap control, and load the corresponding titlesource to this layer for display;
The method is to define two classes inherited from Microsoft. Phone. Controls. Maps. tilesource, And Then override the geturl method;
CodeAs follows:
View code
Public Class Googletitlesource: tilesource { Public Googletitlesource (): Base ( " Http: // KHM {0} .google.com/kh/v?47&x==1}&y=%2}&z=%3 " ){} Public Override Uri geturi ( Int X, Int Y, Int Zoomlevel ){ Return New Uri ( String . Format ( This . Uriformat, X % 4 , X, Y, zoomlevel ));}} Public Class Bingchinatitlesource: tilesource { Public Bingchinatitlesource (): Base ( " Http://r2.tiles.ditu.live.com/tiles/r?quadkey=.png? G = 4 " ){}}
Add the corresponding map layer and source in the page loaded event.
View code
Private Void Phoneapplicationpage_loaded ( Object Sender, routedeventargs e ){ // Bing Maptilelayer bingtilelayer = New Maptilelayer (); bingtilelayer. Width = 431 ; Bingtilelayer. Height = 540 ; Geocoordinate Center = New Geocoordinate ( 36 , 104 ); Tilesource = New Bingchinatitlesource (); bingtilelayer. tilesources. Add (tilesource); bingtilelayer. Opacity = 0.9 ; Bingmap. Children. Add (bingtilelayer); bingmap. Mode = New Mercatormode (); bingmap. Center = Center; // Google Maptilelayer googletilelayer = New Maptilelayer (); googletilelayer. Width = 431 ; Googletilelayer. Height = 540 ; Tilesource googletilesource = New Googletitlesource (); googletilelayer. tilesources. Add (tilesource); googletilelayer. Opacity =0.9 ; Google. Children. Add (googletilelayer); Google. Mode = New Mercatormode (); Google. Center = Center; bingeng. Center = Center ;}
Use the panoramic view in the UI to add two map controls respectively.
View code
<Controls: panorama grid. Row = " 1 " Height = " 722 " Horizontalalignment = " Left " Margin = " 0, 0, 0 " Title = " Maps " Verticalalignment = " Top " Width = " 479 " Fontsize = " 26.667 " Style = " {Staticresource panoramastyle1} " > <Controls: panoramaitem header = " Bing map Chinese " Style = " {Staticresource panoramaitemstyle1} " > <Grid Height = " 579 " Width = " 434 " > <My: Map x: Name = " Bingmap " Height = " 578 " Logovisibility = " Collapsed " Copyrightvisibility = " Collapsed " Horizontalalignment = " Left " Margin = " 3, 1, 0, 0 " Verticalalignment = " Top " Width = " 431 " Zoomlevel = " 3 " /> </GRID> </controls: panoramaitem> <controls: panoramaitem header = " Google Map " Style = " {Staticresource panoramaitemstyle1} " > <Grid Height = " 578 " Width = " 426 " > <My: Map x: Name = " Google " Height = " 578 " Logovisibility = " Collapsed " Copyrightvisibility = " Collapsed " Horizontalalignment = " Left " Margin = " 3, 1, 0, 0 " Verticalalignment = " Top " Width = " 431 " Zoomlevel = " 3 " /> </GRID> </controls: panoramaitem> <controls: panoramaitem header = " Bing map englsh " Style = " {Staticresource panoramaitemstyle1} " > <Grid Height = " 557 " Width = " 426 " > <My: Map x: Name = " Bingeng " Height =" 549 " Zoomlevel = " 3 " Logovisibility = " Collapsed " Copyrightvisibility = " Collapsed " Horizontalalignment = " Left " Margin =" 3, 1, 0, 0 " Verticalalignment = " Top " Width = " 416 " /> </GRID> </controls: panoramaitem> </controls: panorama>
Running Effect
In terms of experience, Bing Chinese and Google seem to be slightly different, but Bing English UI displays too few elements;
Source code