提交 b3761cfa 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor: H5高德地图位置搜索代码优化

上级 1b928357
......@@ -188,43 +188,27 @@ function useList(state: State) {
)
} else if (mapInfo.type === MapType.AMAP) {
window.AMap.plugin('AMap.PlaceSearch', function () {
var autoOptions = {
const placeSearch = new (window.AMap as any).PlaceSearch({
city: '全国',
pageSize: 10,
pageIndex: listState.pageIndex,
}
var placeSearch = new (window.AMap as any).PlaceSearch(autoOptions)
if (state.searching) {
placeSearch.searchNearBy(
state.keyword,
[state.longitude, state.latitude],
50000,
function (status: string, result: any) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
listState.hasNextPage = false
} else {
pushData(result.poiList.pois)
}
}
)
} else {
placeSearch.searchNearBy(
'',
[state.longitude, state.latitude],
5000,
function (status: string, result: any) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
listState.hasNextPage = false
} else {
pushData(result.poiList.pois)
}
})
const keyword = state.searching?state.keyword:''
const radius = state.searching?50000:5000
placeSearch.searchNearBy(
keyword,
[state.longitude, state.latitude],
radius,
function (status: string, result: any) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
listState.hasNextPage = false
} else {
pushData(result.poiList.pois)
}
)
}
}
)
listState.loading = false
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册