谷歌地图(交通地图)上并没有显示某个地址的经纬度,实际上,我们已经想到了一个办法,可以找到在谷歌地图上任意地点的经度和纬度。
首先打开Google地图,在上面寻找一个地址,然后上下左右移动地图,让这个地址正好处于地图的正中心位置,当您想寻找坐标位置已经处于地图的中心位置的时候,拷贝并粘贴以下代码到你的浏览器地址栏:
javascript:void(prompt('',gApplication.getMap().getCenter()));
这时,你将得到一个弹出式的坐标,这个坐标就是你需要找的经度和纬度
第2部分
// 福州平潭岛
string address = "平潭";
// 查询经纬度
string output = "csv";
string key = "abcd";
string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
WebClient wc = new WebClient();
// 读取结果
Stream s = wc.OpenRead(url);
StreamReader sr = new StreamReader(s, Encoding.UTF8);
string result = sr.ReadToEnd();
// 解析 25.499453390583657, 119.79050159454346(HTTP status code, accuracy, latitude, longitude)
string[] tmpArray = result.Split(',');
string latitude = tmpArray[2];
string longitude = tmpArray[3];
MessageBox.Show(string.Format("纬度: {0},经度: {1}", latitude, longitude), address,
MessageBoxButtons.OK, MessageBoxIcon.Information);
使用 HttpWebRequest、HttpWebResponse 类别:
//福州平潭岛
string address = "平潭";
// 查询经纬度
string output = "csv";
string key = "abcde";
string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
// 送出要求
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
// 取得回应
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
// 读取結果
StreamReader sr = new StreamReader(response.GetResponseStream());
// 解析 25.499453390583657, 119.79050159454346(HTTP status code, accuracy, latitude, longitude)
string[] tmpArray = sr.ReadToEnd().Split(',');
string latitude = tmpArray[2];
string longitude = tmpArray[3];
MessageBox.Show(string.Format("纬度: {0}, 经度: {1}", latitude, longitude), address,
MessageBoxButtons.OK, MessageBoxIcon.Information);
发表评论 评论 (0 个评论)