我正在创建一个桌面c#应用程序,它将创建测试文件,但我的问题是文件需要有效地址。有没有办法我可以使用谷歌地图API之一获取有效地址放入我创建的文件?
答案 0 :(得分:2)
您可以使用Google Geocoder API将地址传递到其中并接收有关该位置的数据,例如lat& long坐标,特定地址详细信息等等。使用此数据,您可以验证是否可以说您要限制某个国家或城市的地址。唯一的缺点是每天的请求有限,但应该足够了。
API非常广泛,但我会在下面提供一些链接,以便您了解它。
文档:https://developers.google.com/maps/documentation/geocoding/
示例:https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
另一个例子:http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html
编辑:有关使用地理编码进行地址验证的文章:http://blog.mgm-tp.com/2011/08/address-validation-with-geocoding/
编辑2:以下是关于同一主题的另一篇StackOverflow文章:Address validation using Google Maps API
一个例子回应如下:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Winnetka",
"short_name" : "Winnetka",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New Trier",
"short_name" : "New Trier",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Cook County",
"short_name" : "Cook County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Winnetka, IL, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.7108162
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
},
"location" : {
"lat" : 42.10808340000001,
"lng" : -87.735895
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.1282269,
"lng" : -87.7108162
},
"southwest" : {
"lat" : 42.0886089,
"lng" : -87.7708629
}
}
},
"place_id" : "ChIJW8Va5TnED4gRY91Ng47qy3Q",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}