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

Source: Internet
Author: User

This article is about Windows Phone 7 development on the 31st day"13th day of the series.

Yesterday, we discussed the vibration controller of Windows Phone and how to tell our users to pay attention to what happened on their devices. Today, let's talk about location services and how to get information about their device locations.

Why is location important?

Devices are constantly evolving, and mobile phones have the ability to provide you with custom information that is higher than almost any other device. Especially when talking about the location of the phone. The following are some specific examples (I have sorted them out for this article ):

Procedure for searching documents

Suppose we have an application (or access through the network) that contains circuit diagrams, parts tables, and documents of tens of thousands of products and devices that provide services to customers. On each device, you have to search for the user who is using the device on the current day, find the current office or location, and then parse the required information from the complicated documents.

By adding location information to the program, we do not need to search for users. If each document is labeled with geographic location data, the document at that location is immediately transferred when we approach the building. If we can obtain sufficient location information for a large facility, we can even determine which device is closest to you. The device information is used to determine the specific data to be displayed. It is a way to enhance the program function through location data.

Golf program

I 've seen a lot of golfers that allow you to enter scores, keep records almost, and even share the data with your friends. However, an idea suddenly emerged from my mind.

At the beginning, this app identifies the golf course you are currently on. It will also list nearby stadiums (when you are on the road), so you don't have to look for them. This is a great feature. In addition, it can identify which hole you are in and the distance from the main ground mark of the stadium (sandpits, water, trees, ball points, etc ). The coolest feature I have ever seen is pole analysis. Each time I take a shot, I tell it which one it is. When I go to the place where the ball is located, I will record how far I have taken this shot. If there is enough data, you can even tell me how to get one shot based on the distance between me and the ball hole area. This is a superb application of location data.

Understand location service

We have three methods to obtain the device location. GPS, mobile tracking and positioning, and Wi-Fi location. Next, let's take a quick look at each of the strengths and weaknesses:

Before you start to worry about comparing and comparing the data from three origins, first look at the green cloud maps in the image. Microsoft provides us with a set of location services.

Use location service in Windows Phone 7

There is no code written here. Good news: this may be one of the simplest things you do in your code. Follow these steps:

  1. Create a GeoCoordinateWatcher object.
  2. Create an event handler to handle user location changes.
  3. Capture data when an event is triggered.

You may want to provide users with more functions (which is a good practice in my example), but the simplest example is the following code:

Code 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
{
Public partial class 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 ();
Longpolling. Text = e. Position. Location. longpolling. ToString ();
}
}
}

Like a 11th-day accelerator sensor, the simulator cannot actually obtain location data. (You can check GoeCoordinateWatcher. Status to obtain information ). However, we can use our good friend Reactive Extensions to simulate the data.

There is a great article on MSDN about how to implement it, so I will not repeat it here. Here you can view the Reactive Extensions and location usage on Windows Phone in MSDN.

Download Sample Code

In the example program, I used location services as much as possible. I asked the user to choose between high and default precision, start and stop the service, and even create a map of the current coordinate in the application. Let's try it. It is richer than any of the above examples.

Address: http://www.jeffblankenburg.com/post/31-Days-of-Windows-Phone-7c-Day-13-Location-Services.aspx

 

If you like my article, click "recommendation". Thank you!

 

 

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.