windows phone7 学习笔记14——地理位置服务与反应性扩展框架
使用Location Service能幫助開發者為windows Phone 開發具備位置感知(Location-Aware)功能的應用程序。比如很多導航的軟件,查找附近吃飯、娛樂甚至廁所的應用程序,都是基于這個服務的。
我們有3種方法來獲取設備的位置。GPS,移動網絡基站位置和WiFi位置。下面的圖是這三種方式的優缺點:
?
需要注意的是:windows phone會根據應用程序的需要選擇一種或者多種方式來確定手機的位置。
三種方式確定位置的優點是有效的平衡電池的消耗與位置信息的準確性。
windows phone?為應用程序提供基于事件(event-driven)的統一接口。
?
使用地理位置服務的建議:
- 想辦法減低電池的消耗;
? a.?如果可以的話 使用那個較低準確率的數據源;
?b. ?當需要的時候打開地理位置服務,一旦使用完畢立刻關閉該服務。
- 設置準確率的門限值,減低更新頻率;
- 使用狀態更新事件(StatusChanged)監控服務狀態,提醒用戶狀態的更新;
- 提醒用戶初次啟動地理位置服務時需要等待一段時間(15秒到120秒)。
使用位置服務
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 System.Device.Location;
using Microsoft.Phone.Tasks;
namespace Day13_LocationServices
{
publicpartialclass MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher gcw;
// Constructor
public MainPage()
{
InitializeComponent();
gcw.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gcw_PositionChanged);
gcw.Start();
}
void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
Latitude.Text = e.Position.Location.Latitude.ToString();
Longitude.Text = e.Position.Location.Longitude.ToString();
}
}
}
?
反應性擴展框架(Reactive Extensions)
- Reactive Extensions能夠幫助應用程序把多種可監控的外部事件轉換成異步消息;
- 外部事件包括數據流(data streams),異步請求(asynchronous requests)和事件(event)等;
- 使用Reactive Extensions,當外部時間觸發的時候,應用程序得到異步的更新消息(asynchronous requests);
- Reactive Extensions允許應用程序使用查詢(query)操作來對時間進行過濾。
Windows Phone 7 開發 31 日談——第13日:位置服務
http://www.cnblogs.com/porscheyin/archive/2010/12/23/1914300.html
轉載于:https://www.cnblogs.com/zhangkai2237/archive/2012/02/20/2360619.html
總結
以上是生活随笔為你收集整理的windows phone7 学习笔记14——地理位置服务与反应性扩展框架的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: socket 源码分析
- 下一篇: java信息管理系统总结_java实现科