无法通过使用谷歌澳大利亚地址进行反向地理编码来检索街道、城市和国家
本文关键字:编码 检索 街道 国家 城市 谷歌 地址 澳大利亚 | 更新日期: 2023-09-27 18:27:13
我确实需要从给定地址中提取街道名称、邮政编码、城市、州、国家、纬度和经度
它适用于印度地址,当我尝试澳大利亚地址时,它无法检索街道名称和邮政编码,其余的都可以从JSON数组中的地址组件中检索约束
我使用了谷歌开发者论坛中提到的以下代码
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数组从地址组件中,我需要从澳大利亚地址中检索街道名称、城市、州、邮政编码和国家
请取消阻止此问题
提前感谢
感谢您的回复,我尝试了相同的地址,即;300 George Street,Sydney NSW 2000,Australia,但地址中没有任何内容
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"
}