请问如何输入地址获取地址经纬度呢

Irisene 2009-12-27 02:20:21
求教,谢谢
...全文
1011 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Irisene 2009-12-27
  • 打赏
  • 举报
回复
class Getgeo
{
public struct geo
{
public string Latitude;
public string Longtitude;
}

public static geo Getgeo(
string location)
{

string geo="";
geo mygeo = new geo();
string results = String.Empty;
HttpWebRequest searchRequest =
(HttpWebRequest)WebRequest.Create(@"http://maps.google.com/maps?f=q&geocode=&q="+location +"&output=js");
WebResponse myresponse = searchRequest.GetResponse();
Stream responseStream = myresponse.GetResponseStream();
byte[] buffer = new byte[9999 ];
responseStream.Read(buffer, 0, (int)9999);
results = System.Text.Encoding.ASCII.GetString(buffer);
System.Text.RegularExpressions.Regex myregex = new Regex(@"center..lat\:[^,]+,lng\:.{0,1}[0-9]+.[0-9]+");
MatchCollection mc = myregex.Matches(results);

foreach (Match mymatch in mc)
{
geo = mymatch.Value;
string latitude=geo .Substring (geo .IndexOf ("lat:")+4,5);
string longtitude=geo .Substring (geo .IndexOf ("lng:")+4,5);

mygeo.Latitude = latitude;
mygeo.Longtitude = longtitude;
if (mygeo.Latitude == null)
{
System.Windows.Forms.MessageBox.Show("Null seen");
}
}
myresponse.Close();

responseStream.Close();

myresponse.Close();
return mygeo;
}

public static string GetLongtitude(
string location)
{

geo mygeo = Getgeo(location );
return mygeo.Longtitude;

}


public static string GetLatitude(
string location)
{
geo mygeo = Getgeo(location );
return mygeo.Latitude;

}
}
请问这个代码如何改成我需要的:从一个textbox获取地址,点击按钮,在两个label中显现经纬度,这个怎么引用过来呢
  • 打赏
  • 举报
回复
^:^
wuyq11 2009-12-27
  • 打赏
  • 举报
回复
httpwebrequest通过google map取值
参考
Irisene 2009-12-27
  • 打赏
  • 举报
回复
不管什么都可以,只要能输入一个地址,获取经纬度两个参数就行了,请教大家
Lovely_baby 2009-12-27
  • 打赏
  • 举报
回复

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧