zoukankan
html css js c++ java
C#根据经纬度请求返回坐标实际地址
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; using System.Net; using System.IO; using System.Configuration; using System.Xml; namespace WSGPSGateway.BLL { public class LocationAPI { public static string GetAddressByLatLng(string Lat, string Lng) { string CellUrl = "http://*******/CellAPI.aspx?Lat={0}&Lng={1}&Type=99"; string url = string.Format(CellUrl, Lat.ToString(), Lng.ToString()); string htm = GetPage(url); return htm; } public static string GetPage(string url) { if (url == "") return ""; WebResponse response = null; Stream stream = null; StreamReader reader = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322)"; request.Timeout = 5000; response = request.GetResponse(); stream = response.GetResponseStream(); if (Get_Chartset(response.Headers["Content-Type"].ToString()).ToLower() == "gbk") { reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312")); } else if (Get_Chartset(response.Headers["Content-Type"].ToString()).ToLower() == "utf-8") { reader = new StreamReader(stream, System.Text.Encoding.UTF8); } else { reader = new StreamReader(stream, System.Text.Encoding.UTF8); } string buffer = reader.ReadToEnd(); return buffer; } catch (Exception ex) { DAL.Log.Write("google抓取数据失败异常! \0 错误记录:" + ex + "\r\n"); return ""; } finally { if (reader != null) reader.Close(); if (stream != null) stream.Close(); if (response != null) response.Close(); } } public static string Get_Chartset(string s) { if (s.ToLower() == "text/html") { return "gbk"; } else { int l = s.IndexOf("charset=") + 8; return s.Substring(l, s.Length - l); } } public string GetLatLng(string CID, string LAC) { string Url = "http://********/CellAPI.aspx?cid={0}&lac={1}"; Url = String.Format(Url, CID, LAC); string LatLng = ""; try { LatLng = BLL.LocationAPI.GetPage(Url); } catch (Exception ex) { DAL.Log.Write("获取基站地址发生错误! \0 错误记录:" + ex + "\r\n"); DAL.Log.Write("-----------------------------------------------------------\r\n"); } return LatLng; } } }
查看全文
相关阅读:
蓝桥杯训练 | 枚举,模拟与排序 | 04
linux全套 | Linux模板机器安装 | 18
linux全套 | Shell编程 | 16
MySQL主从复制延迟解决方案
MySQL异地备份方案
MYSQL必知必会-where语句
MySQL常见面试题-概念题
入门-MySQL查询语句的45道练习
20145234黄斐《信息安全系统设计基础》第0周学习总结
OpenGL代码学习(2)
原文地址:https://www.cnblogs.com/javawebsoa/p/2458198.html
最新文章
手摸手,带你用 vue 撸后台 系列一(基础篇)
java 版本EChart使用
Fastjson1.2.24漏洞Fastjson1.2.24反序列化漏洞复现
日报3.12
日报3.11
日报3.10
日报3.9
日报3.8
日报3.7
日报3.6
热门文章
日报3.5
日报3.4
日报3.3
【PHP设计模式】基础知识
docker听课笔记 | 应用部署 | 04
docker听课笔记 | 常用命令 | 03
docker听课笔记 | docker安装与启动 | 02
docker听课笔记 | docker简介 | 01
docker听课笔记 | 目录 | 00
蓝桥杯训练 | 双指针,BFS与图论 | 06
Copyright © 2011-2022 走看看