Ejemplo n.º 1
0
        public static AmapDto WiFiLocation(string key, List <WiFi> wifi, Lbs lbs)
        {
            string url = @"http://apilocate.amap.com/position";

            string arg = $"key={key}&accesstype=1&output=json";

            if (null != wifi && wifi.Count > 0)
            {
                string macs = string.Empty;
                foreach (var w in wifi)
                {
                    macs += $"{MacAddress(w.Mac)},{w.Rssi},|";
                }

                arg += $"&macs={macs.TrimEnd(new char[] { '|' })}";
            }

            var     strResponse = HttpHelper.HttpGet(url, arg);
            AmapDto dto         = JsonConvert.DeserializeObject <AmapDto>(strResponse);

            if (null != dto && "1" == dto.Status && null != dto.Result && dto.Result.Type > 0)
            {
                return(dto);
            }

            return(LbsLocation(key, lbs));
        }
Ejemplo n.º 2
0
        public static AmapDto LbsLocation(string key, Lbs lbs)
        {
            if (null == lbs || null == lbs.Cells || 0 == lbs.Cells.Count)
            {
                return(null);
            }

            string url = @"http://apilocate.amap.com/position";

            string arg = $"key={key}&accesstype=0&cdma=0&output=json";

            int rssi = lbs.Cells[0].RSSI.HasValue ? (int)lbs.Cells[0].RSSI : 49;

            arg += $"&bts={lbs.MCC},{lbs.MNC},{lbs.Cells[0].LAC},{lbs.Cells[0].CI},{rssi}";
            if (lbs.Cells.Count > 1)
            {
                string nearbts = string.Empty;
                for (int i = 1; i < lbs.Cells.Count; i++)
                {
                    Cell cell = lbs.Cells[i];
                    rssi     = cell.RSSI.HasValue ? (int)cell.RSSI : 49;
                    nearbts += $"{lbs.MCC},{lbs.MNC},{cell.LAC},{cell.CI},{rssi}|";
                }

                arg += $"&nearbts={nearbts.TrimEnd(new char[] { '|' })}";
            }

            var     strResponse = HttpHelper.HttpGet(url, arg);
            AmapDto dto         = JsonConvert.DeserializeObject <AmapDto>(strResponse);

            if (null != dto && "1" == dto.Status && null != dto.Result && dto.Result.Type > 0)
            {
                return(dto);
            }

            return(null);
        }