我正在使用Google Geocode验证地址。我遇到一个问题,每当我输入如下所示的输入时 国家:测试,城市:测试 我正在得到如下所示的响应
{
"results": [{
"address_components": [{
"long_name": "7007",
"short_name": "7007",
"types": ["street_number"]
}, {
"long_name": "College Boulevard",
"short_name": "College Blvd",
"types": ["route"]
}, {
"long_name": "Overland Park Plaza",
"short_name": "Overland Park Plaza",
"types": ["neighborhood", "political"]
}, {
"long_name": "Overland Park",
"short_name": "Overland Park",
"types": ["locality", "political"]
}, {
"long_name": "Johnson County",
"short_name": "Johnson County",
"types": ["administrative_area_level_2", "political"]
}, {
"long_name": "Kansas",
"short_name": "KS",
"types": ["administrative_area_level_1", "political"]
}, {
"long_name": "United States",
"short_name": "US",
"types": ["country", "political"]
}, {
"long_name": "66211",
"short_name": "66211",
"types": ["postal_code"]
}],
"formatted_address": "7007 College Blvd, Overland Park, KS 66211, USA",
"geometry": {
"location": {
"lat": 38.92663719999999,
"lng": -94.66484729999999
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 38.92798618029149,
"lng": -94.66349831970848
},
"southwest": {
"lat": 38.9252882197085,
"lng": -94.66619628029149
}
}
},
"place_id": "ChIJPTZ9JzjqwIcR0kOfM1L7n9E",
"plus_code": {
"compound_code": "W8GP+M3 Overland Park, Kansas, United States",
"global_code": "86C7W8GP+M3"
},
"types": ["establishment", "point_of_interest"]
}],
"status": "OK"
}
我不明白对于这样一个不正确的地址,它是如何返回纬度和经度的,任何人都有一个想法请共享.... thnx
答案 0 :(得分:0)
Google Geocoding API不验证地址。它不是故意的。相反,它返回最接近您的输入的地址的纬度。对于您的“测试城市”地址,最接近的匹配项是堪萨斯州。它可能不会很近,但是最接近。
要验证地址,您需要一个地址验证API。我工作的公司名叫YAddress。对于处理的每个地址,它都会告诉您该地址是否有效,如果无效,为什么呢。例如,对于“测试城市”,您将收到错误消息“未找到城市”。