我需要在這裏映射API來自動完成地址。我試圖使用地方建議API,這是記錄:https://developer.here.com/api-explorer/rest/places-search/search-suggestionHere Rest API:如何限制某個區域的建議結果?
但API的行爲令我驚訝。我試圖在華盛頓地區以查詢「20」(部分門牌號碼)得到建議:
curl -X GET -H "X-Map-Viewport: -125.0061,45.6674,-120.6775,48.7269" -H "Cache-Control: no-cache" "https://places.demo.api.here.com/places/v1/suggest?q=20&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&size=5"
{
"suggestions": [
"205th Ave KP S, Lakebay, WA 98349, USA",
"Mall 205",
"204th Avenue KP S, Lakebay, WA 98349, USA",
"202nd Avenue KP S, Lakebay, WA 98349, USA",
"McMenamins"
]
}
這對我來說看起來很好。
curl -X GET -H "X-Map-Viewport: -125.0061,45.6674,-120.6775,48.7269" -H "Cache-Control: no-cache" "https://places.demo.api.here.com/places/v1/suggest?q=2021&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&size=10"
{
"suggestions": [
"2021 California",
"20218, Aguascalientes, Mexico",
"Taco Bell",
"20219, Aguascalientes, Mexico",
"2021 Restaurant",
"20216, Aguascalientes, Mexico",
"2021 Wireless",
"20210, Aguascalientes, Mexico",
"2021.Interactive, LLC",
"20213, Peñas Blancas, Costa Rica"
]
}
我寧願讓沒有結果,如果它不能在比獲得結果的區域找到匹配:
但是當我開始查詢「2021」,它返回我的地址在墨西哥有什麼讓我驚訝的是走出邊界框。
我的問題:我該如何限制搜索範圍?另一個問題是如何過濾掉不是地址的結果?
https://developer.here.com/rest-apis/documentation/places/topics/ location-contexts.html已爲您準備好了 – Onur
我已經通過在示例中將「in」設置爲查詢參數並將「X-Map-Viewport」設置爲標題,嘗試了顯式位置上下文和隱式位置上下文。當我要求華盛頓地區時,這兩個請求都會返回墨西哥地址。 – Bunnyc1986