Introduction to GPS and Web Service in Windows Phone development

Source: Internet
Author: User

Note:
One button, button1, corresponds to a button1_click event, and a textblock, used to display the content. Click this button to get the current GPS coordinate and get the description of the current location based on the coordinate. This application relies on mobile phone GPS hardware support, which cannot be provided by simulators. Call the custom web service method based on the provided GPS longitude and latitude to obtain the location description.

The interface is shown as follows:

The Code is as follows:

Private void button#click (Object sender, routedeventargs e) {// click the key to find my location (depending on the GPS hardware support of the WP mobile phone) geocoordinatewatcher mywatcher = new geocoordinatewatcher (); vaR myposition = mywatcher. position; // Beijing-dimension longitude double latitude = 39.92; double longpolling = 116.46; If (! Myposition. location. isunknown) {latitude = myposition. location. latitude; longpolling = myposition. location. longpolling;} // the text box outputs the longitude and latitude information textblock1.text = "latitude =" + latitude + "\ n" + "longpolling =" + longpolling + "\ n "; // web serive service initialization (usage is different from WM development here, please note) servicereference1.service1soapclient client = new servicereference1.service1soapclient (); client. mylocationcompleted + = new eventhandler <servicereferenc E1.mylocationcompletedeventargs> (client_mylocationcompleted); // call the Web service method client. mylocationasync (latitude, longpolling);} void client_mylocationcompleted (Object sender, servicereference1.mylocationcompletedeventargs e) {// throw new notimplementedexception (); If (E. error! = NULL) {MessageBox. show ("Check the network connection and temporarily cannot access the server. "); return;} else {// receives the returned result textblock1.text + = E. result. tostring ();}}

----------------------------------------------

The Web Service Code is as follows:

Using system; using system. collections; using system. componentmodel; using system. data; using system. LINQ; using system. web; using system. web. services; using system. web. services. protocols; using system. XML. LINQ; namespace lbswebservice {// <summary> // Summary of service1 /// </Summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] [toolboxitem (F ALSE)] // to allow the use of ASP. Net ajax to call this web service from a script, cancel comments to the downstream. // [System. web. script. services. scriptservice] public class service1: system. web. services. webService {[webmethod] Public String mylocation (Double X, Double Y) {// a Web Service string mylocation = "1 Xizhimen North Street, Haidian District, Beijing "; return mylocation ;}}}

TIPS:
When testing a local web service, you do not need to publish the web service. You only need to use the service1.asmx interface as the startup page to browse in the browser. Vs ide will have a simple service to start the program, copy the URL to add it to the WP client as a web reference.

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.