搜索与地址
8.1 POI 关键词、周边与详情
PoiSearch.Query query = new PoiSearch.Query("酒店", "", "");
query.setPageNum(1); query.setPageSize(20);
PoiSearch search = new PoiSearch(context, query);
search.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {
public void onPoiSearched(PoiResult result, int code) {
if (code == SdkException.SUCCESS) report(result.getPois());
else report(search.getLastError());
}
public void onPoiItemSearched(PoiItem item, int code) { report(item); }
});
search.searchPOIAsyn();
// 周边查询:先 setBound,再发起查询。
// search.setBound(new PoiSearch.SearchBound(new LatLonPoint(21.67623,100.02228),1000));
// 已获取Sukha POI ID 后:search.searchPOIIdAsyn(id);
| 参数 | 约束 | 说明 |
|---|---|---|
| keyword | 字符串 | 关键词 |
| type | 字符串,可空 | Sukha数据类别,不保证与高德分类码一致 |
| city | 空字符串或 null | 当前不提供行政城市筛选 |
| pageNum | 1–5,默认 1 | 页号 |
| pageSize | 1–50,默认 20 | 页大小 |
| SearchBound.range | 0–5000 米 | 周边范围 |
| ID | Sukha ID | 不接受高德 POI ID |
同一服务实例的新请求会取消旧请求。需要并行独立查询时分别创建服务对象,共享 SdkClient 即可。
8.2 输入联想
Inputtips tips = new Inputtips(context, new InputtipsQuery("酒店", "").setLimit(10));
tips.setInputtipsListener((items, code) -> {
if (code == SdkException.SUCCESS) report(items); else report(tips.getLastError());
});
tips.requestInputtipsAsyn();
关键词去空白后不能为空,最多 200 字符;limit 为 1–50。下拉 UI 由宿主绘制。监听回调后不要持有已退出 Activity;退出时 destroy。
8.3 正地理编码与逆地理编码
GeocodeSearch geocoder = new GeocodeSearch(context);
geocoder.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
public void onRegeocodeSearched(RegeocodeResult result, int code) {
if (code == SdkException.SUCCESS) report(result.getRegeocodeAddress());
else report(geocoder.getLastError());
}
public void onGeocodeSearched(GeocodeResult result, int code) {
if (code == SdkException.SUCCESS) report(result.getGeocodeAddressList());
}
});
geocoder.getFromLocationNameAsyn(new GeocodeQuery("门店名称", ""));
// 独立执行下面逆查询;不要与上面的正查询同时在同一个对象上执行。
RegeocodeQuery rq = new RegeocodeQuery(new LatLonPoint(21.67623,100.02228),
1000, GeocodeSearch.GPS);
rq.setExtensions("all");
// geocoder.getFromLocationAsyn(rq);
正查询匹配已发布地点/建筑名称,不是完整国内地址解析。逆查询 radius 为 0–3000 米;extensions 为 base/all,默认 base。latLonType 当前只接受 GPS,不能传 AMAP 常量;坐标模式仍由 client 配置。逆查询包含 formattedAddress、匹配信息、POI 和道路,完整省市区门牌不作保证。
同步 getFromLocationName / getFromLocation 只能在工作线程调用。界面优先使用异步接口。