Location service for Windows Phone 7)

Source: Internet
Author: User
Document directory
  • I. Windows Phone 7 Data Retrieval
  • 2. Use geographic location service
Location service for Windows Phone 7)

Location service helps developers develop location-aware applications for Windows phones. Location service can obtain location information from multiple data sources, such as GPS, Wi-Fi, and mobile network base stations. Based on application requirements, location service calculates location information from one or more data sources. Effectively balance battery consumption and accuracy of location information (for example, GPS positioning is less accurate when battery power is low ). Provides unified event-based interfaces for applications. When the geographical location of a user changes, a unique event is triggered and the location is located again to obtain new location information.

I. Windows Phone 7 obtains data from three sources: GPS, Wi-Fi, and mobile base stations.

Windows Phone can obtain geographical information from the above three locations

GPS: the highest precision, but the least power consumption, slow speed, unable to obtain location information indoors.

Wi-Fi: it is rarely used in China. It consumes much less power than GPS, and the speed is faster than GPS. It mainly relies on the background database for locating.

Base station: The accuracy is the lowest, but the speed is fast and the signal strength is good. It mainly uses several base stations to determine the user location. The power consumption is very small and there may be no signal in the field.

2. Use geographic location service

Reference is required

System.Device

And

System.Observable

The two namespaces

The simulator does not provide GPS,. Wi-Fi, and base station services, and the simulator does not provide callback. Therefore, it is impossible to directly implement positioning on the simulator. The simulator can only implement status updates without data return.

Sample Code of the geographic location service:

GeoCoordinateWatcher watcher;
  private void StartButton_Click (object sender, RoutedEventArgs e)
        {
            if (watcher == null)
            {
                //GeoPositionAccuracy.High defines the accuracy level of positioning, High represents high
                watcher = new GeoCoordinateWatcher (GeoPositionAccuracy.High);
                // Indicates the frequency of positioning update, that is, setting the threshold value. High frequency consumes high power, because it needs to locate a new position at any time.
                watcher.MovementThreshold = 20;
                // State change events, such as data change, service stop, etc.
watcher.StatusChanged + = new EventHandler <GeoPositionStatusChangedEventArgs> (watcher_StatusChanged);
                // Position change events, such as longitude, latitude, altitude, etc.
watcher.PositionChanged + = new EventHandler <GeoPositionChangedEventArgs <GeoCoordinate >> (watcher_PositionChanged);
watcher.Start ();
            }
        }
void watcher_PositionChanged (object sender,
 GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            Dispatcher.BeginInvoke (() =>
            {
                // Get latitude coordinates
                this.LatitudeTextBox.Text = e.Position.Location.Latitude.ToString ();
                // Get longitude coordinates
                this.LongitudeTextBox.Text = e.Position.Location.Longitude.ToString ();
            });
        }

        void watcher_StatusChanged (object sender, GeoPositionStatusChangedEventArgs e)
        {
            Dispatcher.BeginInvoke (() =>
                {
                    StatusTextBox.Text = e.Status.ToString ();
                });
        } 


For the above content, refer to the video of Jake Lin.

(All Rights Reserved. For details, refer to the source)

Related Article

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.