您可以使用Google Maps Geocoding API
(为了使用它,你需要一个Gecoding API key)
对于您的示例“500 W 133rd St, New York, NY 10027, USA”,您可以通过以下方式调用 API:
https://maps.googleapis.com/maps/api/geocode/json?address=500%20W%20133rd%20St,%20New%20York,%20NY%2010027,%20USA
如果您提供正确的密钥,您应该会得到以下 JSON:
{
"results" : [
{
"address_components" : [
{
"long_name" : "500",
"short_name" : "500",
"types" : [ "street_number" ]
},
{
"long_name" : "West 133rd Street",
"short_name" : "W 133rd St",
"types" : [ "route" ]
},
{
"long_name" : "Upper Manhattan",
"short_name" : "Upper Manhattan",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Manhattan",
"short_name" : "Manhattan",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York County",
"short_name" : "New York County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Stany Zjednoczone",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "10027",
"short_name" : "10027",
"types" : [ "postal_code" ]
},
{
"long_name" : "7302",
"short_name" : "7302",
"types" : [ "postal_code_suffix" ]
}
],
"formatted_address" : "500 W 133rd St, New York, NY 10027, Stany Zjednoczone",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.8176249,
"lng" : -73.9532346
},
"southwest" : {
"lat" : 40.8176127,
"lng" : -73.9532442
}
},
"location" : {
"lat" : 40.8176127,
"lng" : -73.9532442
},
"location_type" : "RANGE_INTERPOLATED",
"viewport" : {
"northeast" : {
"lat" : 40.81896778029149,
"lng" : -73.9518904197085
},
"southwest" : {
"lat" : 40.81626981970849,
"lng" : -73.95458838029151
}
}
},
"place_id" : "Eic1MDAgVyAxMzNyZCBTdCwgTmV3IFlvcmssIE5ZIDEwMDI3LCBVU0E",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
您可以过滤掉 neighborhood、sublocality_level_1 或 postal_code 类型并获取相关的 long_name 以搜索多边形。