使用官方的uni-map-common 的地点搜索api出现的

1***@qq.com
- 发布:2023-08-14 09:45
- 更新:2023-08-14 11:10
- 阅读:261
产品分类: uniCloud/App
操作步骤:
预期结果:
查询出地点结果
查询出地点结果
实际结果:
Cannot read properties of undefined (reading 'lat')
Cannot read properties of undefined (reading 'lat')
bug描述:
官方的uni-map-common 的地点搜索api的示例传参如下:
let result = await uniMap.search({
keyword: "酒店",
boundary: "nearby(39.908815,116.397507,1000,1)"
city: "北京市"
});
示例中的boundary参数是将经纬度进行拼接后作为入参传入。
而地点搜索api中则无此boundary参数,而是经度、纬度作为参数在api中进行的拼接,如下:
async search(data = {}) {
let {
keyword,
location,
radius = 1000,
auto_extend = 1,
get_subpois,
orderby,
page_index = 1,
page_size = 20,
filter,
} = data;
if (radius < 10) radius = 10;
let boundary = `nearby(${location.lat},${location.lng},${radius},${auto_extend})`;
let requestData = {
keyword,
boundary,
get_subpois,
filter,
orderby: orderby === "distance" ? "_distance" : undefined,
page_index,
page_size
};
故此处前后参数矛盾,此处会报错 Cannot read properties of undefined (reading 'lat')
2 个回复
1***@qq.com (作者)
将地点搜索api中的参数加上boundary ,并将boundary 的拼接删除就可以了,或者在参数中传入经纬度,而不是boundary,最终代码如下:
DCloud_uniCloud_VK
文档上的示例有问题,文档上的请求参数是对的,用location表示而不直接用boundary是为了方便兼容其他地图供应商
1***@qq.com (作者)
竟然是VK大佬回复了,感谢感谢,这个问题我已经自己解决了
2023-08-15 08:41