使用没有UI的Google Maps SDK解析完整地址



我有一个地址列表,没有格式化,也不一定写正确。

我想在这些破碎的地址字符串上迭代,并使用谷歌地图sdk之一接收更结构化和完整的地址

基本上我有两个问题:

  1. 哪个SDK最适合这个任务?(有40个列表)
  2. 我如何使用它没有UI?(我看到的所有解决方案都包括UI和搜索框)

如果你正在使用google-maps SDK,你可能正在寻找地理编码API

它可以不使用UI,因为它也可以通过这个端点作为json获取:

https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters

为例:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,
+Mountain+View,+CA&key=YOUR_API_KEY

或通过JS api:

geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': 'Mountain View, CA'}, function(results, status) {
if (status == 'OK') {
console.log(results);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});

结果:

{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"plus_code": {
"compound_code": "CWC8+W5 Mountain View, California, United States",
"global_code": "849VCWC8+W5"
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}

相关内容

  • 没有找到相关文章

最新更新