基于GPS实时信号的WebGIS模拟[1]

Posted by 蒋波涛 30 March,2010 Views (2)Comment

很早以前我就对GPS的实时显示感兴趣,一般物流或其他需要实施监控的企业采用的跟踪系统都是C/S的,后来我在一个Demo上看到过基于B/S的例子,主要是基于AGS JSAPI开发而成的。我也曾专门问过相关的人,证实了我对该技术实现流程的猜测,即客户端定期访问一个指定的WebService来获取GPS信号,然后将其在地图上显示。

GPS信号模拟软件我没有找到,所以我就自己写了一个随机坐标生成服务,它能够提供一个指定范围内的坐标点:

GPSPoint类代码:

    public class GPSPoint
    {
        private int x;
        private int y;
        public GPSPoint()
        {
        }
        public int X
        {
            get { return x; }
            set { x = value; }
        }

        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        public string createJSON()
        {
            StringBuilder JsonString = new StringBuilder();
            JsonString.Append("{");
            JsonString.Append("\"GPSPoint\":[ ");
            JsonString.Append("\"" + x.ToString() + "\"," + "\"" + y.ToString() + "\"");
            JsonString.Append("]}");
            return JsonString.ToString();

        }
    }

该WebService方法:

        [WebMethod]
        public string CreateGPSInfo()
        {
            Random ram=new Random();
            int x=ram.Next(586742, 621223);
            int y = ram.Next(89212, 117049);
            GPSPoint pt=new GPSPoint();
            pt.X = x;
            pt.Y = y;
            return pt.createJSON();
        }

.NET20的WebService一个比较讨厌的地方是无法以JSON格式将数据返回给客户端,因此我还写了一个ashx的文件,专门返回JSON格式的数据:

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            GPS gps = new GPS();

            context.Response.Write(gps.CreateGPSInfo());
        }

 在客户端该如何定时请求GPS服务并显示呢?这其实也并不复杂。

Related Items

Categories : ArcGIS Server Tags : ArcGIS Server  JSAPI  ExtJS  
Comments
2010-4-27 14:59:29

问一下浩淼兄,在ae里面有没有类似于mapobject中trackinglayer的动态图层,动态显示类似gps数据的类或接口?

Posted by 76er Gravatar Icon

2010-4-27 15:38:01

有的,AE里面的samples中还有个这方面的例子

Posted by 蒋波涛 Gravatar Icon

Leave a comment

Or, take a look at Archives and Categories

目录

存档