我有一個地址串列,沒有格式化,也不一定寫得正確。
我想迭代這些損壞的地址字串,并使用 Google Maps SDK 之一接收更結構化和完整的地址
基本上我有兩個問題:
- 哪個 SDK 最適合這項任務?(有40個串列)
- 如何在沒有 UI 的情況下使用它?(我看到的所有解決方案都包括 UI 和搜索框)
uj5u.com熱心網友回復:
如果您實際上使用的是 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"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/343811.html
