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; } } }
查看全文
相关阅读:
记2008年7月25日午后 心情
[多媒体]词典编码
[多媒体]算术编码、游程编码
[多媒体]数据压缩的类型
[多媒体]理解PCM、DPCM、APCM、ADPCM
C++异常处理
[转]linux上SVN解决冲突的办法
从海量数据查找有或者没有出现的数据
八数码问题
[转]linux中强大的screen命令
原文地址:https://www.cnblogs.com/javawebsoa/p/2458198.html
最新文章
AJAX基础教程及初步使用
仿新浪自定义对话框演示
嵌套gridview ,repeater
存储过程
实体类自动生成小程序
HDU 3650 差分
UVA 10173 旋转卡壳
UVA 10522 已知三高求三角型面积
POJ 2079/HDU 3934 旋转卡壳
HDU 3007 最小覆盖圆
热门文章
ZOJ 3058 两圆相交面积
POJ 1279 半平面交
UVA 10347 已知三中线求三角形面积
ZOJ 2589 欧拉公式
POJ 1474 半平面交
javascript调用ie打印机
EditPlus编译你的flex(转)
Flex Builder 3.0 plugin 在 Zend 中的安装
[多媒体]什么是VGA接口
希腊字母表及其读音与意义
Copyright © 2011-2022 走看看