目前,我可以通过我的Google Geocode API发送shsihsigsuygdjhgadjhg
,并返回APPROXIMATE
位置类型 - 即使我刚刚完成了它!
根据文档,我已将请求限制为仅GB(英国),但如何将其限制为仅返回true
位置?
参数:
$param = ['address' => 'shsihsigsuygdjhgadjhg','components' => 'country:GB'];
响应:
$response = \Geocoder::geocode('json', $param);
$decoded_response = json_decode($response);
回复是:
+"results": array:1 [▼
0 => {#314 ▼
+"address_components": array:1 [▼
0 => {#313 ▼
+"long_name": "United Kingdom"
+"short_name": "GB"
+"types": array:2 [▼
0 => "country"
1 => "political"
]
}
]
+"formatted_address": "United Kingdom"
+"geometry": {#320 ▼
+"bounds": {#131 ▶}
+"location": {#321 ▶}
+"location_type": "APPROXIMATE"
+"viewport": {#323 ▶}
}
+"partial_match": true
+"place_id": "ChIJqZHHQhE7WgIReiWIMkOg-MQ"
+"types": array:2 [▼
0 => "country"
1 => "political"
]
}
]
+"status": "OK"
}
如何确保它为大致位置返回ZERO_RESULTS
?
答案 0 :(得分:1)
不是添加组件字段,而是将国家/地区值添加到地址字段本身。组件字段尝试在您指定的值内获取组件。它无法识别您传入的地址,但它识别该国家/地区,因此您获得了部分匹配。
而不是
$param = ['address' => 'shsihsigsuygdjhgadjhg','components' => 'country:GB'];
尝试,
$param = ['address' => 'shsihsigsuygdjhgadjhg, GB'];
我为第二次实施获得零结果。