您可以使用Google Maps Geocoding API (爲了使用它,你需要一個Gecoding API key)
對於你的榜樣「500瓦第133街,紐約,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
來搜索多邊形。
我早些時候嘗試了上述內容,但並未將其用於以下兩個原因。 1)它不返回哈萊姆,你可以直觀地看到哈萊姆是地圖上的區域。 2)當我嘗試了其他幾個地址時,它將sublocality_level_2作爲較窄/較小的區域返回,但在諸如您的情況下,只會提到sublocality_level_1,但確實存在鄰域。任何想法是什麼? –
我想哈林是一個多邊形的空間物體,但不是地區結構的一部分(如果我們問哈林,我們將把曼哈頓作爲最精確的區域): https://maps.googleapis.com/maps/ api/geocode/json?address = Harlem,New%20York,%20NY%2010027,%20USA –
另一個想法是您嘗試使用Nominatim(OpenStreetMap上的服務),採用類似的兩步方法: Discover id:http: //nominatim.openstreetmap.org/search?q=500%20W%20133rd%20St,%20New%20York,%20NY%2010027,%20USA&format=json 使用ID獲取詳細信息:http://nominatim.openstreetmap。 org/details.php?place_id = 1672811647 儘管至少在Nominatim中你還沒有得到Harlem的結構,你將從OpenStreetMap獲得對象的ID,所以它應該更容易應用步驟 –