Windows phone7 Study Notes 14-geographic location service and reactive extension framework

Source: Internet
Author: User

Location service helps developers develop location-aware applications for Windows phones. For example, a lot of navigation software and applications that search for nearby meals, entertainment, and even toilets are based on this service.

We have three methods to obtain the device location. GPS, mobile network base station location and WiFi location. The following figure shows the advantages and disadvantages of the three methods:

 

Note that Windows Phone will choose one or more methods to determine the location of the mobile phone based on the application's needs.

The advantage of the three methods to determine the position is to effectively balance the consumption of the battery and the accuracy of the location information.

Windows Phone provides a unified event-driven interface for applications.

 

  Suggestions for using the geographic location service:

  • Find ways to reduce battery consumption;

A. If possible, use the data source with lower accuracy;

B. Enable the location service as needed. Once the service is ready for use, it is immediately disabled.

  • Set the threshold of accuracy to reduce the update frequency;
  • Use the status update event (statuschanged) to monitor the service status and remind users to update the status;
  • Remind the user to wait for a period of time (15 seconds to 120 seconds) when starting the geographic location service for the first time ).
 

  Location service

  1. Create a geocoordinatewatcher object.
  2. Create an event handler to handle user location changes.
  3. Capture data when an event is triggered.
    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 can help applications convert multiple monitored external events into asynchronous messages;
  • External events include data streamams, asynchronous requests, and events;
  • When reactive extensions is used, the application receives an asynchronous update message (asynchronous requests) when the external time is triggered );
  • Reactive Extensions allows applications to filter time using query operations.
For more information about how to use reactive extensions, see the http://msdn.microsoft.com/en-us/library/ff637517 (vs.92) in msdn ). aspx reference: 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

Discussion on Windows Phone 7 development on the 31st day-13th: location service

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.