步骤如下:
配置完成后运行示例代码:
import { site } from '@kit.MapKit'; @Entry @Component struct Index { async poiSearch(){ let params: site.SearchByTextParams = { // 指定关键字,xxx需替换具体地址 query: "xxxxxxxx", // 经纬度坐标 location: { latitude: 34.19390192547735, longitude: 108.87269875520396 }, // 指定地理位置的范围半径 radius: 10000, language: "zh" }; // 返回关键字搜索结果 const result = await site.searchByText(params); console.log("搜索结果:",JSON.stringify(result)); } build() { Column() { Button('click').onClick(async ()=>{ await this.poiSearch(); }) } .width("100%") .height("100%") .justifyContent(FlexAlign.Center) } }
Q:使用POI关键字搜索省份/城市信息为什么只返回一条数据?
A:搜索区划信息时返回最准确的一个,如搜索出关键字相关的地点可以使用自动补全接口:queryAutoComplete。
Q:花瓣地图如何监听点击POI对象?
A:建议使用on('poiClick')监听POI点击事件。支持传递多个callback异步回调。