对于城市,你可以试试这个方法
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=new delhi&types=locality&key=Your_API_Key
响应
{
"predictions": [
{
"description": "New Delhi, Delhi, India",
"matched_substrings": [
{
"length": 9,
"offset": 0
}
],
"place_id": "ChIJLbZ-NFv9DDkRzk0gTkm3wlI",
"reference": "ChIJLbZ-NFv9DDkRzk0gTkm3wlI",
"structured_formatting": {
"main_text": "New Delhi",
"main_text_matched_substrings": [
{
"length": 9,
"offset": 0
}
],
"secondary_text": "Delhi, India"
},
"terms": [
{
"offset": 0,
"value": "New Delhi"
},
{
"offset": 11,
"value": "Delhi"
},
{
"offset": 18,
"value": "India"
}
],
"types": [
"locality",
"political",
"geocode"
]
},
{
"description": "New Delhi, Madhya Pradesh, India",
"matched_substrings": [
{
"length": 9,
"offset": 0
}
],
"place_id": "ChIJF6eOnlmqhTkR2f8IfiLL4bs",
"reference": "ChIJF6eOnlmqhTkR2f8IfiLL4bs",
"structured_formatting": {
"main_text": "New Delhi",
"main_text_matched_substrings": [
{
"length": 9,
"offset": 0
}
],
"secondary_text": "Madhya Pradesh, India"
},
"terms": [
{
"offset": 0,
"value": "New Delhi"
},
{
"offset": 11,
"value": "Madhya Pradesh"
},
{
"offset": 27,
"value": "India"
}
],
"types": [
"locality",
"political",
"geocode"
]
},
{
"description": "Delhi, NY, USA",
"matched_substrings": [
{
"length": 5,
"offset": 0
}
],
"place_id": "ChIJVS4Od-R43IkRReeLGEBFcv8",
"reference": "ChIJVS4Od-R43IkRReeLGEBFcv8",
"structured_formatting": {
"main_text": "Delhi",
"main_text_matched_substrings": [
{
"length": 5,
"offset": 0
}
],
"secondary_text": "NY, USA"
},
"terms": [
{
"offset": 0,
"value": "Delhi"
},
{
"offset": 7,
"value": "NY"
},
{
"offset": 11,
"value": "USA"
}
],
"types": [
"locality",
"political",
"geocode"
]
}
],
"status": "OK"
}