Places Autocomplete API 并非旨在支持“子前提”结果。不久前在https://issuetracker.google.com/35830389的公共问题跟踪器中报告并回答了这一问题
子前提结果的澳大利亚地址看起来与街道地址/前提结果的地址“足够接近”(它们大多以数字开头)。这目前导致 Place Autocomplete 返回可能看起来像子前提结果的内容,但请注意该类型仍然是“路线”:
http://maps.googleapis.com/maps/api/place/autocomplete/json?input=9/321%20Pitt%20Street,%20Sydney
description: "9/321 Pitt Street, Sydney NSW, Australia",
place_id: "Eig5LzMyMSBQaXR0IFN0cmVldCwgU3lkbmV5IE5TVywgQXVzdHJhbGlh",
types: ["route","geocode",],
带有此 place_id 的地点详细信息(和地理编码)请求实际上会找到正确的子前提结果:
https://maps.googleapis.com/maps/api/place/details/json?placeid=Eig5LzMyMSBQaXR0IFN0cmVldCwgU3lkbmV5IE5TVywgQXVzdHJhbGlh
"result" : {
"address_components" : [
{
"long_name" : "9",
"short_name" : "9",
"types" : [ "subpremise" ]
},
{
"long_name" : "321",
"short_name" : "321",
"types" : [ "street_number" ]
},
...
"formatted_address" : "9/321 Pitt St, Sydney NSW 2000, Australia",
"types" : [ "subpremise" ],
但是,这不能保证适用于所有子前提查询,甚至不能保证长期适用于这个特定的查询。
更可靠的方法是使用 Geocoding API 来搜索预测的“描述”:
https://maps.googleapis.com/maps/api/geocode/json?&address=9%2F321%20Pitt%20St%2C%20Sydney%20NSW%202000%2C%20Australia
"results" : [
{
"address_components" : [
{
"long_name" : "9",
"short_name" : "9",
"types" : [ "subpremise" ]
},
{
"long_name" : "321",
"short_name" : "321",
"types" : [ "street_number" ]
},
...
],
"formatted_address" : "9/321 Pitt St, Sydney NSW 2000, Australia",
"place_id" : "Eik5LzMyMSBQaXR0IFN0LCBTeWRuZXkgTlNXIDIwMDAsIEF1c3RyYWxpYSIdGhsKFgoUChIJkyPU0z2uEmsR-pmiK6UvZUASATk",
"types" : [ "subpremise" ]