Windows Phone开发之GPS、Web Service服务使用简介
2012-05-29 18:26
666 查看
说明:
一个按钮button1,对应一个button1_click事件,一个TextBlock,用来显示内容。点击该按钮可以得到当前GPS坐标,并根据坐标得出当前所在的位置描述。该应用依赖于手机GPS的硬件支持,模拟器提供不了。根据提供的GPS的经纬度调用自定义的Web Service方法来得到位置描述。
界面图如下:
代码如下:
----------------------------------------------
Web Service代码如下:
小技巧:
本地Web Service测试时,没必要将该Web Service服务发布,只需要将Service1.asmx界面作为启动页在浏览器浏览。VS IDE会有简易服务启动该程序,将该地址URL复制即可添加到WP客户端作为web引用。
一个按钮button1,对应一个button1_click事件,一个TextBlock,用来显示内容。点击该按钮可以得到当前GPS坐标,并根据坐标得出当前所在的位置描述。该应用依赖于手机GPS的硬件支持,模拟器提供不了。根据提供的GPS的经纬度调用自定义的Web Service方法来得到位置描述。
界面图如下:
代码如下:
private void button1_Click(object sender, RoutedEventArgs e) { //点击按键 找到我的位置(依赖于WP手机的GPS硬件支持) GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher(); var myPosition = myWatcher.Position; //北京维度 经度 double latitude = 39.92; double longitude = 116.46; if (!myPosition.Location.IsUnknown) { latitude = myPosition.Location.Latitude; longitude = myPosition.Location.Longitude; } //文本框输出经纬度信息 textBlock1.Text = "latitude==" + latitude + "\n" + "longitude==" + longitude+"\n"; //Web serive服务初始化(此处用法与WM开发有不同,需注意) ServiceReference1.Service1SoapClient client = new ServiceReference1.Service1SoapClient(); client.myLocationCompleted +=new EventHandler<ServiceReference1.myLocationCompletedEventArgs>(client_myLocationCompleted); //调用Web Service方法 client.myLocationAsync(latitude, longitude); } void client_myLocationCompleted(object sender, ServiceReference1.myLocationCompletedEventArgs e) { //throw new NotImplementedException(); if(e.Error!=null){ MessageBox.Show("请检查网络连接,暂时访问不到服务端."); return; }else{ //接收返回结果 textBlock1.Text += e.Result.ToString(); } }
----------------------------------------------
Web Service代码如下:
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> /// Service1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod] public string myLocation(double x,double y) { //自己随便写的一个Web Service服务 string myLocation="北京海淀区西直门北大街1号"; return myLocation; } } }
小技巧:
本地Web Service测试时,没必要将该Web Service服务发布,只需要将Service1.asmx界面作为启动页在浏览器浏览。VS IDE会有简易服务启动该程序,将该地址URL复制即可添加到WP客户端作为web引用。
相关文章推荐
- Web Service 那点事儿(4)—— 使用 CXF 开发 REST 服务
- [置顶]Android 项目开发 基于Web Service 服务的中英翻译软件(四)使用Sqlite “辅助” Web Service
- Web Service 那点事儿(4)—— 使用 CXF 开发 REST 服务
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- Web Service 那点事儿(4)—— 使用 CXF 开发 REST 服务
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- Android 项目开发 基于Web Service 服务的中英翻译软件(四)使用Sqlite “辅助” Web Service
- 使用CXF开发web service服务中报错
- Web Service 那点事儿(4)—— 使用 CXF 开发 REST 服务
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- 使用CXF开发Web Service服务
- Web Service那些事 2/4 - 使用 CXF 开发 SOAP 服务
- iOS开发masonry的一些使用简介
- 腾讯云容器服务的滚动升级使用简介
- 使用SpringBoot开发Restful服务实现增删改查功能
- 安卓开发:服务的更多技巧--1.使用前台服务
- 王晓东原创:C# 简易IDE开发工具-快速创建Windows和Web程序及Web Service服务!
- 使用SOAP开发WebService 服务--Axis解决方案
- 使用PhoneGap开发windows phone 7 应用(1)-初识PhoneGap