windows phone7 學習筆記14——地理位置服務與反應性擴充架構

來源:互聯網
上載者:User

  使用Location Service能協助開發人員為windows Phone 開發具備位置感知(Location-Aware)功能的應用程式。比如很多導航的軟體,尋找附近吃飯、娛樂甚至廁所的應用程式,都是基於這個服務的。

  我們有3種方法來擷取裝置的位置。GPS,移動網路基站位置和WiFi位置。下面的圖是這三種方式的優缺點:

 

  需要注意的是:windows phone會根據應用程式的需要選擇一種或者多種方式來確定手機的位置。

  三種方式確定位置的優點是有效平衡電池的消耗與位置資訊的準確性。

  windows phone 為應用程式提供基於事件(event-driven)的統一介面。

 

  使用地理位置服務的建議:

  • 想辦法減低電池的消耗;

      a. 如果可以的話 使用那個較低準確率的資料來源;

      b.  當需要的時候開啟地理位置服務,一旦使用完畢立刻關閉該服務。

  • 設定準確率的門限值,減低更新頻率;
  • 使用狀態更新事件(StatusChanged)監控服務狀態,提醒使用者狀態的更新;
  • 提醒使用者初次啟動地理位置服務時需要等待一段時間(15秒到120秒)。
 

  使用位置服務

  1. 建立一個GeoCoordinateWatcher對象。
  2. 建立一個事件處理常式處理使用者位置的改變。
  3. 在事件觸發時抓取資料。
    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 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)操作來對時間進行過濾。
    如何使用Reactive Extensions可以參考msdn的這篇文章:http://msdn.microsoft.com/en-us/library/ff637517(VS.92).aspx     參考資料:How to: Get Data from the Location Service for Windows Phone       http://msdn.microsoft.com/en-us/library/ff431782(v=vs.92).aspx       How to: Use Reactive Extensions to Emulate and Filter Location Data for Windows Phone       http://msdn.microsoft.com/en-us/library/ff637517(VS.92).aspx

       Windows Phone 7 開發 31 日談——第13日:位置服務

       http://www.cnblogs.com/porscheyin/archive/2010/12/23/1914300.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.