Starting from today's development, we have started a new journey. We need to familiarize ourselves with the starters and selectors in the next course. In fact, they are the same and there is no fundamental difference between them, the starter has returned results. For example, if you open the search application to search, and the selector has returned content, select a photo.
So what are the starters and selectors? In fact, we can simply understand it. To put it bluntly, we use the built-in components or applications. That's right. As I said, sometimes many concepts are just names that are scary. Actually, they are very simple to use, such as the starter and selector.
Is it very easy? I will know it in practice. This series of tutorials is called "easy getting started". Since it is easy, it won't be difficult for everyone to do things. MS has always paid attention to user experience, it won't make everyone suffer.
To sum up, the method of using the initiator and Selector is the same, but the selector has one more step because of the returned content.
1. instantiate a component, that is, a new component;
2. Set related parameters or attributes. For example, if you want to make a phone call, you must set a number. Otherwise, you may need to set a bird;
3. display the application components. Now that the system program is called for user operations, show them;
4. (optional) process the returned data, which is available in the selector.
Today, let's talk about the first component, bingmapsdirectionstask, which is to start Bing map to locate and search the route. Is it like a navigation system?
There are two ways to use this starter. One is through the start and end labels, that is, from where to where, such as from Wuhan to Shanghai, the start label is Wuhan, and the end label is Shanghai; another method is the start and end positions, such as longitude and latitude.
First, let's demonstrate how to use tags for navigation.
The interface is very simple. I believe that through the previous study, we all know how to get it done, as long as you can enter the start and end labels.
The following is the background C # code:
[CSHARP]View plaincopyprint?
- 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 Microsoft. Phone. tasks;
- Namespace launchersample
- {
- Public partial class mapbylabel: phoneapplicationpage
- {
- Public mapbylabel ()
- {
- Initializecomponent ();
- }
- Private void button#click (Object sender, routedeventargs E)
- {
- Bingmapsdirectionstask map = new bingmapsdirectionstask ();
- Map. Start = new labeledmaplocation {label = txtlabelstart. Text };
- Map. End = new labeledmaplocation {label = txtlabelend. Text };
- Map. Show ();
- }
- }
- }
Remember to introduce the Microsoft. Phone. Tasks space where all the starters and selectors are located.
Next, we can use the longitude and latitude to locate the problem.
First, add a reference, right-click "Reference" in the project, add a reference, and then select system. device. OK.
Then, complete the interface, as shown in the preceding figure, the longitude and latitude of the start point and the end point.
Then there is the code.
[CSHARP]View plaincopyprint?
- 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;
- // Introduce the following namespace
- Using Microsoft. Phone. tasks;
- Using system. device. location;
- Namespace launchersample
- {
- Public partial class bingmapsample: phoneapplicationpage
- {
- Public bingmapsample ()
- {
- Initializecomponent ();
- }
- Private void button#click (Object sender, routedeventargs E)
- {
- Bingmapsdirectionstask bt = new bingmapsdirectionstask ();
- // Start position
- Labeledmaplocation locstart = new labeledmaplocation ();
- Locstart. Location = new geocoordinate (convert. todouble (txtlatitudestart. Text), convert. todouble (txtlongitudestart. Text ));
- // End position
- Labeledmaplocation locend = new labeledmaplocation ();
- Locend. Location = new geocoordinate (convert. todouble (txtlatitudeend. Text), convert. todouble (txtlongitudeend. Text ));
- // Set attributes
- Bt. Start = locstart;
- Bt. End = locend;
- // Display the Initiator
- Bt. Show ();
- }
- }
- }