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:
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. net; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. animation; <br/> using system. windows. shapes; <br/> using Microsoft. phone. controls; <br/> using Microsoft. phone. tasks; </P> <p> namespace launchersample <br/>{< br/> Public partial class mapbylabel: phoneapplicationpage <br/>{< br/> Public mapbylabel () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void button#click (Object sender, routedeventargs E) <br/>{< br/> bingmapsdirectionstask map = new bingmapsdirectionstask (); <br/> map. start = new labeledmaplocation {label = txtlabelstart. text };< br/> map. end = new labeledmaplocation {label = txtlabelend. text };< br/> map. show (); <br/>}< br/>}
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.
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. net; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. animation; <br/> using system. windows. shapes; <br/> using Microsoft. phone. controls; <br/> // introduce the following namespace <br/> using Microsoft. phone. tasks; <br/> using system. device. location; </P> <p> namespace launchersample <br/>{< br/> Public partial class bingmapsample: phoneapplicationpage <br/>{< br/> Public bingmapsample () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void button#click (Object sender, routedeventargs E) <br/>{< br/> bingmapsdirectionstask bt = new bingmapsdirectionstask (); <br/> // start position <br/> labeledmaplocation locstart = new labeledmaplocation (); <br/> locstart. location = new geocoordinate (convert. todouble (txtlatitudestart. text), convert. todouble (txtlongitudestart. text); <br/> // end position <br/> labeledmaplocation locend = new labeledmaplocation (); <br/> locend. location = new geocoordinate (convert. todouble (txtlatitudeend. text), convert. todouble (txtlongitudeend. text); <br/> // set attributes <br/> BT. start = locstart; <br/> BT. end = locend; <br/> // display the starter <br/> BT. show (); <br/>}< br/>}