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

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

上级 b87ad91d
...@@ -269,33 +269,22 @@ export default { ...@@ -269,33 +269,22 @@ export default {
const self = this const self = this
window.AMap.plugin('AMap.PlaceSearch', function () { window.AMap.plugin('AMap.PlaceSearch', function () {
var autoOptions = { const placeSearch = new window.AMap.PlaceSearch({
city: '全国', city: '全国',
pageSize: 10, pageSize: 10,
pageIndex: self.pageIndex pageIndex: self.pageIndex
} })
var placeSearch = new window.AMap.PlaceSearch(autoOptions) const keyword = self.searching ? self.keyword : ''
if (self.searching) { const radius = self.searching ? 50000 : 5000
placeSearch.searchNearBy(self.keyword, [self.longitude, self.latitude], 50000, function (status, result) { placeSearch.searchNearBy(keyword, [self.longitude, self.latitude], radius, function (status, result) {
if (status === 'error') { if (status === 'error') {
console.error(result) console.error(result)
} else if (status === 'no_data') { } else if (status === 'no_data') {
self.hasNextPage = false self.hasNextPage = false
} else { } else {
self.pushData(result.poiList.pois) self.pushData(result.poiList.pois)
} }
}) })
} else {
placeSearch.searchNearBy('', [self.longitude, self.latitude], 5000, function (status, result) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
self.hasNextPage = false
} else {
self.pushData(result.poiList.pois)
}
})
}
self.loading = false self.loading = false
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册