windows8 Metro环境下Bing Map SDK的安装与使用
来源:互联网 发布:淘宝优惠券入口 编辑:程序博客网 时间:2024/05/25 08:14
必应地图现在有了针对Windows Store App的SDK,可以很方便的把Bing地图功能整合到自己的应用当中。
最近参照官方说明文档操作了一下,果然比较好用,记录下经过以备日后使用。
1.环境安装
操作系统: Windows8 Pro 64bit (RTM)
开发工具: Microsoft Visual Studio Professional 2012(RTM)
SDK: Bing Maps SDK for Windows Store apps
注:如果操作系统是Windows 8 Release Preview,需要安装对应的预览版用SDK Bing Maps SDK for Windows Store apps
2.创建Bing Map Account,并创建Bing Map Key
登录https://www.bingmapsportal.com,如果已经有了一个Windows Live ID,点击sign用Windows Live ID登录并创建Bing Map Account。
点击页面左侧[My Account]里的[Create or view keys],输入信息后点击Submit以创建Bing Map Key,创建完成后在画面下方可以查看到生成的Bing Map Key
是一个64位英数字符号混合的字串。
3.下载官方实例 Bing Maps C# LocationTracking Sample
- 程序运行前,需要先确认References中Bing Maps Application for Windows Store的参照正确无误。
- 在代码中全局搜索INSERT_YOUR_BING_MAPS_KEY字串,使用生成的Bing Map Key替换之。
- 在Solution Explorer窗口中右击Solution,从弹出菜单中选择Properties,将Configuration Properties中的Platform由ARM改为x64。
- 编译运行。
4.代码相关
要使用BingMap功能,最主要的就是Map控件,在XAML文件中定义入下:
<bm:Map x:Name="map" Credentials="INSERT_YOUR_BING_MAPS_KEY" Width="800" Height="450"/>
好了,这样应用中就有了最基本的Bing地图功能了,超简单吧。
下面是调整Map属性的代码:
map.MapType = MapType.Road; //道路模式 map.MapType = MapType.Aerial; //航空摄影模式 map.MapType = MapType.Birdseye; //鸟瞰模式 map.Heading += 90; //逆时针旋转90度 map.Heading -= 90; //顺时针旋转90度 TimeSpan animationDuration = new TimeSpan(0, 0, 0, 0, 500); //设定延迟加载时间 map.SetHeading(map.Heading - 90, animationDuration); //旋转90度后延迟加载地图
接下来结合定位功能:
LocationIcon locationIcon; Geoposition currentPosition = await geolocator.GetGeopositionAsync(); Location location = new Location(currentPosition .Coordinate.Latitude, currentPosition .Coordinate.Longitude); map.SetView(location, 10.0f);
现在地图的中点就是当前的位置了。
在地图上添加图钉,XAML上直接定义:
<bm:Map ZoomLevel="10" Credentials="INSERT_YOUR_BING_MAPS_KEY" > <bm:Map.Center> <bm:Location Latitude="47.610039" Longitude="-122.342207" /> </bm:Map.Center> <bm:Map.Children> <bm:Pushpin> <bm:MapLayer.Position> <bm:Location Latitude="47.610039" Longitude="-122.342207" /> </bm:MapLayer.Position> </bm:Pushpin> </bm:Map.Children> </bm:Map>
在代码中为制定坐标添加图钉:
MapLayer mPinLayer = new MapLayer(); map.Children.Add(mPinLayer); LocationCollection mPolyShapeLocations = new LocationCollection(); mPolyShapeLocations.Add(new Location(15, -15)); mPolyShapeLocations.Add(new Location(30, -90)); mPolyShapeLocations.Add(new Location(-45, -15)); mPolyShapeLocations.Add(new Location(30, 90)); mPolyShapeLocations.Add(new Location(60, 60)); for (int i = 0; i < mPolyShapeLocations.Count; i++) { Pushpin pin = new Pushpin(); pin.Text = i.ToString(); mPinLayer.Children.Add(pin); MapLayer.SetPosition(pin, mPolyShapeLocations[i]); }
结合上面的代码,设定图钉后,再在各个指定坐标间连线:
MapLayer mPinLayer = new MapLayer(); map.Children.Add(mPinLayer); MapShapeLayer mShapeLayer = new MapShapeLayer(); map.ShapeLayers.Add(mShapeLayer); LocationCollection mPolyShapeLocations = new LocationCollection(); mPolyShapeLocations.Add(new Location(15, -15)); mPolyShapeLocations.Add(new Location(30, -90)); mPolyShapeLocations.Add(new Location(-45, -15)); mPolyShapeLocations.Add(new Location(30, 90)); mPolyShapeLocations.Add(new Location(60, 60)); for (int i = 0; i < mPolyShapeLocations.Count; i++) { Pushpin pin = new Pushpin(); pin.Text = i.ToString(); mPinLayer.Children.Add(pin); MapLayer.SetPosition(pin, mPolyShapeLocations[i]); } MapPolyline polyline = new MapPolyline(); polyline.Color = Windows.UI.Colors.Red; polyline.Locations = mPolyShapeLocations; mShapeLayer.Shapes.Add(mapShape);
至此,已经对Bing Map SDK 的安装和使用做了简单的说明,对于Metro App中内嵌Bing Map功能的需求,应该可以满足大部分的使用需要了。
- windows8 Metro环境下Bing Map SDK的安装与使用
- Windows8下MySQL的安装与配置
- Windows8.1下安装Driectx sdk
- 微软发布为Windows 8 Metro程序使用Bing Maps SDK
- Windows8.1 Python 环境下安装OpenCV
- 【Windows8开发】Metro App生命周期之打包、部署安装与卸载
- 关闭Windows8启动时的Metro界面
- Windows8.1 64bit环境下搭建深度学习平台之CUDA安装与配置
- Windows8.1 64bit环境下搭建深度学习平台之CUDA安装与配置
- Windows8.1 64bit环境下搭建深度学习平台之CUDA安装与配置
- Windows8 环境下的 jekyll 本地搭建
- Android SDK的安装与环境配置
- windows8.1下安装python2的pip
- Windows8下安装Docker
- Windows8下使用Oracle10G的忧伤
- windows8下RmySQL包的使用
- Windows8浅谈之Metro与经典Windows界面
- 【windows8开发】Metro App生命周期之Suspended与Resume
- C/C++常见笔试面试题-03(高质量编程)
- linux解压 tar命令
- 47.黑马程序员-IO流缓冲区、装饰设计模式
- 北京否认公积金申请爆棚致批贷速度放慢-北京-公积金-爆棚
- EBS根据表单、功能反查其职责、菜单路径
- windows8 Metro环境下Bing Map SDK的安装与使用
- Android联系人模块分析(二)
- demod -a
- makefile中关于all和.PHONY .cpp.o
- [技巧]使用Xcode集成的HeaderDoc自动生成注释和开发文档
- 军方称获总政表彰女军人与27岁女上校非同一人-任婕-假军人-假冒军官
- Exadata遭遇ORA-27603和ORA-27626
- web测试的一些经验分享
- 负载均衡 统一接入层方案