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; } } }
查看全文
相关阅读:
springmvc 之 url映射restful 及 ant
springmvc 之 处理方法的返回值类型
springmvc 之 数据处理
springmvc 之 使用注解开发springmvc
springmvc 之 配置及流程
springmvc 之 springmvc简介,开发步骤
mybatis 之 mybatis整合spring
mybatis 之 mybatis缓存
mybatis 之 mybatis的映射
SuperMap iClient3D for WebGL教程 水面特效制作
原文地址:https://www.cnblogs.com/javawebsoa/p/2458198.html
最新文章
学习进度表第二周
按Right-BICEP的测试用例
四则运算第二版
构建之法阅读笔记02
学习进度表
随机生成30道四则运算(一)
软件工程本学期阅读计划
自我介绍
《大道至简——软件工程实践者的思想》读后感(一)
第六周学习进度
热门文章
《构建之法》阅读笔记04-代码规范
最大连通子数组
安卓版四则运算
团队介绍
《构建之法》阅读笔记03-团队合作
第五周学习进度
二维数组求最大子矩阵的和
第四周学习进度
日志
springmvc 之 文件上传
Copyright © 2011-2022 走看看