c# – 无法通过反向地理编码使用谷歌检索街道,城市和国家澳大利亚地址
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 无法通过反向地理编码使用谷歌检索街道,城市和国家澳大利亚地址,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2732字,纯文字阅读大概需要4分钟。
内容图文
![c# – 无法通过反向地理编码使用谷歌检索街道,城市和国家澳大利亚地址](/upload/InfoBanner/zyjiaocheng/771/8510b75df8ee449285f511828fd1820b.jpg)
我确实需要从给定地址中提取街道名称,邮政编码,城市,州,国家,纬度,经度
它适用于印度地址,当我尝试使用澳大利亚地址时,它无法检索街道名称和邮政编码其余的东西可以很好地从JSON数组中的地址组件中检索约束
我使用了以下代码,这些代码在Google开发人员论坛中引用
public void FrmGoogleGeoCode(string frmAddress)
{
string addUrl = "http://maps.google.com/maps/api/geocode/json?address='" + frmAddress + "'&sensor=false";
var result = new System.Net.WebClient().DownloadString(addUrl);
GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result);
var response = test.results.First();
}
在var结果中,我得到地址组件和格式化地址的JSON数组
从地址组件我需要从澳大利亚地址检索街道名称,城市,州,邮政编码和国家
请解除此问题的阻止
提前致谢
解决方法:
感谢您的回复,我尝试了相同的地址,即澳大利亚悉尼新南威尔士州2000乔治街300号,但回复中的地址没有任何要素
frmAddress ="300 George Street, Sydney NSW 2000, Australia";
这是我以下代码检索街道名称,城市,郊区,国家,邮政编码
string addUrl = "http://maps.google.com/maps/api/geocode/json?address='" + frmAddress + "'&sensor=false";
var result = new System.Net.WebClient().DownloadString(addUrl);
GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result);
var response = test.results.First();
string route=null;
string locality=null;
string pstlCode = null;
for (int i = 0; i < response.address_components.Count(); i++)
{
int j = 0;
var components = response.address_components[i];
string type = components.types[j].ToString();
if (type == "route")
{
route = response.address_components[i].long_name.ToString();
}
if (type == "locality")
{
locality = response.address_components[i].long_name.ToString();
}
if (type == "postal_code")
{
pstlCode = response.address_components[i].long_name.ToString();
}
}
frmLocation = route +","+locality +","+ pstlCode;
然后我用这段代码尝试了乔治街,悉尼,新南威尔士州,2000年,澳大利亚.
这是以下回复.请您发布代码,以便对我有所帮助.
{ "results" : [ {"address_components" : [
{
"long_name" : "George Street",
"short_name" : "George Street",
"types" : [ "colloquial_area", "political" ]
},
{
"long_name" : "New South Wales",
"short_name" : "NSW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "George Street, NSW, Australia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -33.9134399,
"lng" : 151.1667177
},
"southwest" : {
"lat" : -34.0059442,
"lng" : 151.0332033
}
},
"location" : {
"lat" : -33.9547504,
"lng" : 151.1053691
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -33.9134399,
"lng" : 151.1667177
},
"southwest" : {
"lat" : -34.0059442,
"lng" : 151.0332033
}
}
},
"partial_match" : true,
"types" : [ "colloquial_area", "political" ]
}
],
"status" : "OK"
}
内容总结
以上是互联网集市为您收集整理的c# – 无法通过反向地理编码使用谷歌检索街道,城市和国家澳大利亚地址全部内容,希望文章能够帮你解决c# – 无法通过反向地理编码使用谷歌检索街道,城市和国家澳大利亚地址所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。