WP7个人学习日志110630:关于如何加载中文地图及疑惑

下午开始看有关地图加载的视频,因Map控件默认加载的是Bing地图,所以是英文的,经过一翻网上查阅后,晚上在Map控件上加载了Google的地图,中文显示,甚是高兴,但却不知加载Google地图地址(“http://mt{0}.google.com/vt/lyrs=m@107&hl=en&x={1}&y={2}&z={3}&s=Ga”)和重载函数(“public override Uri GetUri(int x, int y, int zoomLevel)”)的具体意思,有待研究,在此也请教看到此文章的大侠们能给予帮助,多谢指导O(∩_∩)O~
基本代码示例如下:
先建立一个加载谷歌地图的类MyGoogleTileSource继承与TileSource,此代码来自网络他人所写,不是很明白,希望大侠能给以指导
public class MyGoogleTileSource:TileSource { public MyGoogleTileSource() : base("http://mt{0}.google.com/vt/lyrs=m@107&hl=en&x={1}&y={2}&z={3}&s=Ga") { } public override Uri GetUri(int x, int y, int zoomLevel) { //return base.GetUri(x, y, zoomLevel); int num = ((x & 1) << 1) | (y & 1); return new Uri(string.Format(this.UriFormat, num, x, y, zoomLevel)); } }


在页面添加命名空间
xmlns:local="clr-namespace:MyBingMap"(此处的MyBingMap是我建立此项目的命名空间名,改为自己的即可)
xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
xmlns:mycore="clr-namespace:Microsoft.Phone.Controls.Maps.Core;assembly=Microsoft.Phone.Controls.Maps"(引用此空间的具体作用还希望看到的大侠给解说一下,谢谢)
添加一Map控件BingMap,在此Map控件中调用此类,加载Google地图,默认地图中心坐标是济南附近

添加两个TextBox控件txtLatitude和txtLongitude,用于填写纬度和精度,添加一个Button控件btnCenter用于定位,实现Button控件btnCenter的Click事件,具体代码如下: private void btnCenter_Click(object sender, RoutedEventArgs e) { if (txtLatitude.Text != "" || txtLongitude.Text != "") { double latitude = 0; double longitude = 0; double.TryParse(txtLatitude.Text, out latitude); double.TryParse(txtLongitude.Text, out longitude); BingMap.SetView(new GeoCoordinate(latitude, longitude), 10); } else { BingMap.SetView(new GeoCoordinate(36.66, 117), 10); } }

再添加两个实现缩放地图大小的Button控件btnElarge和btnLessen用于调节地图级别,实现各自的Click事件,代码如下: private void btnElarge_Click(object sender, RoutedEventArgs e) { BingMap.ZoomLevel++; } private void btnLessen_Click(object sender, RoutedEventArgs e) { BingMap.ZoomLevel--; }
由于本人也是初学基于Silverlight的WP7程序开发,还希望大侠们能多给予帮助,谢谢O(∩_∩)O~
效果如图所示:
WP7个人学习日志110630:关于如何加载中文地图及疑惑WP7个人学习日志110630:关于如何加载中文地图及疑惑WP7个人学习日志110630:关于如何加载中文地图及疑惑
Tags: 

延伸阅读

最新评论

发表评论