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
- Create a geocoordinatewatcher object.
- Create an event handler to handle user location changes.
- 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