Windows Phone开发(22):启动器与选择器之BingMapsDirectionsTask .

从今天开发始,我们又开始新的征程,接下来的课程我们要熟悉一下启动器和选择器,其实二者是一样的,没有根本的区别,启动器是有返回结果的,如打开搜索应用程序进行搜索,而选择器是有返回内容的,如选择一张照片。

 

那么,启动器和选择器是啥玩意儿呢?其实我们可以很简单去理解,说白了,就是使用系自带的组件或应用程序。对的,就是这样,我说过,有时候很多概念只是名字上吓人罢了,实际用起来是非常简单的,比如这个启动器和选择器就是了。

 

到底是不是很简单,实践一下就知道了,本系列教程叫“轻松入门”,既然称得上是轻松,痛苦的事情不会叫大家去做,而MS一向注重用户体验,不会让大家痛苦的。

先来总结一下,使用启动器和选择器的方法是一样的,都是以下几步,不过选择器因为有返回内容,因此会多一步。

一、实例化组件,就是new一个;

二、设置相关参数或属性,比如你要打电话,你总得要设置一个号码吧,不然你打个鸟啊;

三、显示应用组件,既然调用了系统程序,让用户操作,当然要Show出来;

四、(可选)处理返回数据,这是选择器才有。

 

今天先讲第一个组件,BingMapsDirectionsTask,就是启动Bing地图对行车路线进行定位搜索,是啊,像导航系统吧?

 

有两种方法来使用该启动器,一是通过开始和结束标签,就是从哪里到哪里,如从武汉到上海,那么开始标签为Wuhan,结束标签为Shanghai;另一种方法是通开始和结束位置,如经度,纬度等。

 

首先,我们演示一下简单的,用标签来导航。

 

界面很简单了,相信通过前面的学习,大家都知道怎么弄了,只要能输入开始和结束标签即。

下面是后台C#代码:

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using Microsoft.Phone.Controls;  
  13. using Microsoft.Phone.Tasks;  
  14.   
  15. namespace LauncherSample  
  16. {  
  17.     public partial class MapByLabel : PhoneApplicationPage  
  18.     {  
  19.         public MapByLabel()  
  20.         {  
  21.             InitializeComponent();  
  22.         }  
  23.   
  24.         private void button1_Click(object sender, RoutedEventArgs e)  
  25.         {  
  26.             BingMapsDirectionsTask map = new BingMapsDirectionsTask();  
  27.             map.Start = new LabeledMapLocation { Label = txtLabelStart.Text };  
  28.             map.End = new LabeledMapLocation { Label = txtLabelEnd.Text };  
  29.             map.Show();  
  30.         }  
  31.     }  
  32. }  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace LauncherSample
{
    public partial class MapByLabel : PhoneApplicationPage
    {
        public MapByLabel()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            BingMapsDirectionsTask map = new BingMapsDirectionsTask();
            map.Start = new LabeledMapLocation { Label = txtLabelStart.Text };
            map.End = new LabeledMapLocation { Label = txtLabelEnd.Text };
            map.Show();
        }
    }
}


 

记得引入Microsoft.Phone.Tasks空间,所有的启动器和选择器都在里面。

 

 

 

好接下来,我们用能过经度和纬度来定位的方法。

 

首先要添加一个引用,在项目中右击“引用”,添加引用,然后选择System.Device,确定。

 

接着做好界面,同上需要开始的经度纬度,以及结束位置的经纬度。

 

 

然后就是代码。

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using Microsoft.Phone.Controls;  
  13. // 引入以下命名空间   
  14. using Microsoft.Phone.Tasks;  
  15. using System.Device.Location;  
  16.   
  17. namespace LauncherSample  
  18. {  
  19.     public partial class BingMapSample : PhoneApplicationPage  
  20.     {  
  21.         public BingMapSample()  
  22.         {  
  23.             InitializeComponent();  
  24.         }  
  25.   
  26.         private void button1_Click(object sender, RoutedEventArgs e)  
  27.         {  
  28.             BingMapsDirectionsTask bt = new BingMapsDirectionsTask();  
  29.             // 开始位置   
  30.             LabeledMapLocation locStart = new LabeledMapLocation();  
  31.             locStart.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeStart.Text), Convert.ToDouble(txtLongitudeStart.Text));  
  32.             // 结束位置   
  33.             LabeledMapLocation locEnd = new LabeledMapLocation();  
  34.             locEnd.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeEnd.Text), Convert.ToDouble(txtLongitudeEnd.Text));  
  35.             // 设置属性   
  36.             bt.Start = locStart;  
  37.             bt.End = locEnd;  
  38.             // 显示启动器   
  39.             bt.Show();  
  40.         }  
  41.     }  
  42. }  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
// 引入以下命名空间
using Microsoft.Phone.Tasks;
using System.Device.Location;

namespace LauncherSample
{
    public partial class BingMapSample : PhoneApplicationPage
    {
        public BingMapSample()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            BingMapsDirectionsTask bt = new BingMapsDirectionsTask();
            // 开始位置
            LabeledMapLocation locStart = new LabeledMapLocation();
            locStart.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeStart.Text), Convert.ToDouble(txtLongitudeStart.Text));
            // 结束位置
            LabeledMapLocation locEnd = new LabeledMapLocation();
            locEnd.Location = new GeoCoordinate(Convert.ToDouble(txtLatitudeEnd.Text), Convert.ToDouble(txtLongitudeEnd.Text));
            // 设置属性
            bt.Start = locStart;
            bt.End = locEnd;
            // 显示启动器
            bt.Show();
        }
    }
}


基于STM32F407,使用DFS算法实现最短迷宫路径检索,分为三种模式:1.DEBUG模式,2. 训练模式,3. 主程序模式 ,DEBUG模式主要分析bug,测量必要数据,训练模式用于DFS算法训练最短路径,并将最短路径以链表形式存储Flash, 主程序模式从Flash中….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值