GPS经纬度值 转换成 区域
2013-10-31 08:55
274 查看
开始准备用百度API,要什么秘钥,太麻烦了,找了个GOOGLE的
如下网址内容可参考
http://www.cnblogs.com/liuhaorain/archive/2012/01/31/2334018.html
这里有PC和PDA平台2中:
PC下转换:
//webclient客户端对象
WebClient client = new WebClient();
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
client.Encoding = Encoding.UTF8;//编码格式
string responseTest = client.DownloadString(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK") {
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
address = address + "," + area;
}
}
PDA下:
void Getarea( string longitude,string latitude)
{
////webclient客户端对象
//WebClient client = new WebClient();
//string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
//client.Encoding = Encoding.UTF8;//编码格式
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
//string responseTest = client.DownloadString(url);
string responseTest = GetData(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK")
{
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
label4.Text = address + "," + area;
//address = address + "," + area;
Addtxt(address + "," + area);
}
}
}
string GetData(string url)
{
try
{
HttpWebRequest myRequst = (HttpWebRequest)WebRequest.Create(url);
myRequst.Method = "GET";
myRequst.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)myRequst.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("UTF-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
return retString;
}
catch (System.Exception ex)
{
return string.Empty;
}
}
如下网址内容可参考
http://www.cnblogs.com/liuhaorain/archive/2012/01/31/2334018.html
这里有PC和PDA平台2中:
PC下转换:
//webclient客户端对象
WebClient client = new WebClient();
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
client.Encoding = Encoding.UTF8;//编码格式
string responseTest = client.DownloadString(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK") {
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
address = address + "," + area;
}
}
PDA下:
void Getarea( string longitude,string latitude)
{
////webclient客户端对象
//WebClient client = new WebClient();
//string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
//client.Encoding = Encoding.UTF8;//编码格式
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//请求地址
//string responseTest = client.DownloadString(url);
string responseTest = GetData(url);
//下载xml响应数据
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//创建XML文档对象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加载xml字符串
//查询状态信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK")
{
//查询详细地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查询地区信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");
XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示筛选type='sublocality'的所有相关子节点;
XmlNode idtst = idts[0];
string area = idtst.SelectSingleNode("short_name").InnerText;
label4.Text = address + "," + area;
//address = address + "," + area;
Addtxt(address + "," + area);
}
}
}
string GetData(string url)
{
try
{
HttpWebRequest myRequst = (HttpWebRequest)WebRequest.Create(url);
myRequst.Method = "GET";
myRequst.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)myRequst.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("UTF-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
return retString;
}
catch (System.Exception ex)
{
return string.Empty;
}
}
相关文章推荐
- 通过百度地图API将百度坐标转换成GPS经纬度
- 经由过程百度地图API,将百度坐标转换成GPS经纬度
- 各地图gps坐标系统比较与转换以及经纬度距离计算MATLAB脚本
- [转] GPS坐标转换经纬度及换算方法
- Google地图百度地图GPS经纬度偏移转换(JAVA)
- 根据经纬度计算距离的公式、百度坐标转换成GPS坐标(PHP版)
- Android 学习意外第五季<2>——google GPS定位由经纬度转换地址信息
- GPS经纬度转换屏幕坐标
- IOS将GPS定位经纬度转换为高德地图经纬度
- GPS\谷歌\AMAP等地图经纬度转换为百度地图经纬度
- 【转】GPS经纬度数据转换到以米单位的平面坐标系
- GPS经纬度坐标的转换
- GPS坐标转换经纬度及换算方法
- GPS设备定位的经纬度偏移转换
- GPS 转换成百度经纬度
- 通过百度地图API,将百度坐标转换成GPS经纬度
- 高德地图与GPS经纬度转换
- 百度地图经纬度转换+反地址解析+显示可视区域内标注点+地图自动刷新+标注的聚合
- 通过百度地图API,将百度坐标转换成GPS经纬度
- GPS怎么把经纬度转换成标准的度分秒单位