Appearance
搜索服务 API
搜索 SDK(com.sfmap.api.search.*)提供 9 个异步搜索接口,统一 SFMSearchListener 回调(主线程),API 风格对齐高德搜索 SDK。功能说明与示例见 搜索服务。
涉及类全部位于包 com.sfmap.api.search 及其子包下:
| 类 / 接口 | 包 | 说明 |
|---|---|---|
SFMSearch | search | 搜索 API 入口 |
SFMSearchListener | search | 搜索回调监听器 |
SFMSearchErrorCode | search.core | 错误码常量 |
SFMSearchConfig | search.core | 服务 host / ak / 端点路径配置 |
InputTipsQuery / KeywordQuery | search.query | 输入提示 / 地址搜索参数 |
GeocodeQuery / ReGeocodeQuery | search.query | 地理编码 / 逆地理编码参数 |
DrivingRouteQuery / TruckRouteQuery | search.query | 车行 / 货车(高阶)路径规划参数 |
BikeRouteQuery / WalkRouteQuery | search.query | 骑行 / 步行路径规划参数 |
DistrictQuery | search.query | 行政区划查询参数 |
LatLonPoint | search.model | 经纬度坐标 |
Tip / Poi | search.model | 输入提示项 / POI |
GeocodeResult / ReGeocodeResult / ReGeocodePoi | search.model | 编码结果模型 |
DrivingRouteResult / BikeRouteResult / RoutePath / RouteStep | search.model | 路径规划结果模型 |
DistrictResult / DistrictItem / DistrictPolygon | search.model | 行政区划结果模型 |
SFMSearch
com.sfmap.api.search.SFMSearch
搜索 API 入口。所有异步方法均要求先 setListener,否则请求被忽略(仅输出错误日志)。回调在主线程。
构造方法
| 方法签名 | 说明 |
|---|---|
SFMSearch(Context context) | 构造搜索实例,内部持有 applicationContext,可复用 |
公共方法
| 方法签名 | 说明 |
|---|---|
void setListener(SFMSearchListener listener) | 设置搜索回调监听器 |
void cancelAll() | 取消所有待处理请求(在途请求的回调被丢弃),建议页面销毁时调用 |
void searchInputTipsAsyn(InputTipsQuery query) | 输入提示(异步),对应 /opsdkapi/v2/bs/tips;query/region 必填 |
void searchKeywordAsyn(KeywordQuery query) | 地址搜索(异步),对应 /opsdkapi/v2/place/search;query/region 必填 |
void searchGeocodeAsyn(GeocodeQuery query) | 地理编码(异步),对应 /opsdkapi/v2/geocode/geo;address 必填 |
void searchReGeocodeAsyn(ReGeocodeQuery query) | 逆地理编码(异步),对应 /opsdkapi/v2/geocode/rgeo;坐标不能为 (0,0) |
void calculateDrivingRouteAsyn(DrivingRouteQuery query) | 车行路径规划(异步),对应 /opsdkapi/v2/middleService/normalCarRoutePlan;起终点坐标/地址二选一 |
void calculateTruckRouteAsyn(TruckRouteQuery query) | 货车路径规划·高阶(异步),对应 /opsdkapi/v2/middleService/carRoutePlan;支持完整货车参数 |
void calculateBikeRouteAsyn(BikeRouteQuery query) | 骑行路径规划(异步),对应 /opsdkapi/v2/middleService/bikeRoutePlan(travelType 1 自行车 / 2 电动车);起终点坐标必填 |
void calculateWalkRouteAsyn(WalkRouteQuery query) | 步行路径规划(异步),同骑行端点(travelType 固定 3);起终点坐标必填 |
void searchDistrictAsyn(DistrictQuery query) | 行政区划查询(异步),对应 /opsdkapi/v2/getCityInfo;adarea 必填 |
SFMSearchListener
com.sfmap.api.search.SFMSearchListener
搜索回调监听器。成功时回调对应 onXxxSearched;失败时统一回调 onSearchError,对应成功回调不触发。所有回调均在主线程。接口方法(无 default,须全部实现或由父类承接):
| 方法签名 | 说明 |
|---|---|
void onInputTipsSearched(InputTipsQuery query, List<Tip> tips) | 输入提示返回 |
void onKeywordSearched(KeywordQuery query, List<Poi> pois) | 地址搜索返回 |
void onGeocodeSearched(GeocodeQuery query, GeocodeResult result) | 地理编码返回(地址 → 坐标) |
void onReGeocodeSearched(ReGeocodeQuery query, ReGeocodeResult result) | 逆地理编码返回(坐标 → 地址) |
void onDrivingRouteSearched(DrivingRouteQuery query, DrivingRouteResult result) | 车行路径规划返回 |
void onTruckRouteSearched(TruckRouteQuery query, DrivingRouteResult result) | 货车路径规划(高阶)返回 |
void onBikeRouteSearched(BikeRouteQuery query, BikeRouteResult result) | 骑行路径规划返回(自行车/电动车由 query.ridingType 区分) |
void onWalkRouteSearched(WalkRouteQuery query, BikeRouteResult result) | 步行路径规划返回 |
void onDistrictSearched(DistrictQuery query, DistrictResult result) | 行政区划查询返回(showSubLevel=1 时 districts 项含下级列表) |
default void onSearchError(int rCode, String message) | 搜索失败统一回调,rCode 见 SFMSearchErrorCode |
SFMSearchErrorCode
com.sfmap.api.search.core.SFMSearchErrorCode
| 常量 | 值 | 说明 |
|---|---|---|
OK | 1000 | 成功 |
INVALID_PARAMETER | 1001 | 参数校验失败 |
NETWORK_ERROR | 1002 | 网络请求失败 |
MISSING_AK | 1003 | 未配置 ak |
SERVICE_ERROR | 1004 | 服务端业务错误(status != 0 / success != true) |
GATEWAY_ERROR | 1005 | 网关错误 |
PARSE_ERROR | 1006 | 响应解析失败 |
SFMSearchConfig
com.sfmap.api.search.core.SFMSearchConfig
搜索服务配置(单例,getInstance() 获取)。
| 方法签名 | 说明 |
|---|---|
static SFMSearchConfig getInstance() | 获取单例 |
String getHost(Context context) | 取搜索 host(对齐 iOS SFMapSearchServer):运行时覆盖 > assets sfmap_configer.data 的 search_server_url > Manifest meta-data(com.sfmap.searchServer)> 默认生产 host(https://gis-apis.sf-express.com) |
void setHost(String host) | 运行时覆盖搜索 host |
String getApiKey() | 搜索独立 ak(未设置时回落底图 ak) |
void setApiKey(String apiKey) | 设置搜索独立 ak(与底图 ak 分离,开放平台单独申请时使用) |
String getTipsPath() / setTipsPath(String) | 输入提示端点路径(默认 /opsdkapi/v2/bs/tips) |
String getPlaceSearchPath() / setPlaceSearchPath(String) | 地址搜索端点路径(默认 /opsdkapi/v2/place/search) |
String getGeoPath() / setGeoPath(String) | 地理编码端点路径(默认 /opsdkapi/v2/geocode/geo) |
String getRgeoPath() / setRgeoPath(String) | 逆地理编码端点路径(默认 /opsdkapi/v2/geocode/rgeo) |
String getDrivingPath() / setDrivingPath(String) | 车行规划端点路径(默认 /opsdkapi/v2/middleService/normalCarRoutePlan) |
String getTruckPath() / setTruckPath(String) | 货车规划端点路径(默认 /opsdkapi/v2/middleService/carRoutePlan) |
String getRidingPath() / setRidingPath(String) | 骑行/步行端点路径(默认 /opsdkapi/v2/middleService/bikeRoutePlan) |
String getDistrictPath() / setDistrictPath(String) | 行政区划端点路径(默认 /opsdkapi/v2/getCityInfo) |
LatLonPoint
com.sfmap.api.search.model.LatLonPoint
经纬度坐标(对齐高德 LatLonPoint)。构造器纬度在前,与 ReGeocodeQuery(经度在前)相反,注意区分。
| 方法签名 | 说明 |
|---|---|
LatLonPoint() | 空构造 |
LatLonPoint(double latitude, double longitude) | 纬度在前构造 |
double getLatitude() / setLatitude(double) | 纬度 |
double getLongitude() / setLongitude(double) | 经度 |
输入提示 / 地址搜索参数
InputTipsQuery
com.sfmap.api.search.query.InputTipsQuery(/opsdkapi/v2/bs/tips,GET)
| 方法签名 | 说明 |
|---|---|
InputTipsQuery(String query, String region) | 关键字 + 城市(adcode 或城市名),均必填 |
String getQuery() | 搜索关键字 |
String getRegion() | 城市 |
InputTipsQuery pageNum(int) / getPageNum() | 页码,默认 1 |
InputTipsQuery pageSize(int) / getPageSize() | 页大小,默认 10 |
KeywordQuery
com.sfmap.api.search.query.KeywordQuery(/opsdkapi/v2/place/search,GET)
方法集与 InputTipsQuery 完全一致(query / region 必填,pageNum / pageSize 分页)。
编码参数
GeocodeQuery
com.sfmap.api.search.query.GeocodeQuery(/opsdkapi/v2/geocode/geo,GET)
| 方法签名 | 说明 |
|---|---|
GeocodeQuery(String address, String city) | 待编码地址(必填)+ 城市 |
String getAddress() | 地址 |
String getCity() | 城市名 / adcode |
GeocodeQuery cc(int) / getCc() | 坐标系,默认 0 |
ReGeocodeQuery
com.sfmap.api.search.query.ReGeocodeQuery(/opsdkapi/v2/geocode/rgeo,GET)
| 方法签名 | 说明 |
|---|---|
ReGeocodeQuery(double longitude, double latitude) | 坐标,经度在前,不能为 (0,0) |
double getLongitude() / getLatitude() | 经度 / 纬度 |
ReGeocodeQuery range(int) / getRange() | 周边 POI 检索半径(米),>0 时生效 |
路径规划参数
DrivingRouteQuery
com.sfmap.api.search.query.DrivingRouteQuery(/opsdkapi/v2/middleService/normalCarRoutePlan,POST JSON)。起终点支持坐标或地址文本(坐标优先)。链式 setter 均返回 this。
| 方法签名 | 说明 |
|---|---|
DrivingRouteQuery(LatLonPoint origin, LatLonPoint destination) | 坐标起终点 |
DrivingRouteQuery originAddr(String) / getOriginAddr() | 起点 address 文本(无坐标时使用) |
DrivingRouteQuery destinationAddr(String) / getDestinationAddr() | 终点 address 文本 |
DrivingRouteQuery strategy(int) / getStrategy() | 路线策略,默认 0 |
DrivingRouteQuery opt(String) / getOpt() | 算法选项,默认 "2" |
DrivingRouteQuery vehicle(String) / getVehicle() | 车型 |
DrivingRouteQuery weight(double) / getWeight() | 总重(吨),>0 生效 |
DrivingRouteQuery height(double) / getHeight() | 车高(米),>0 生效 |
DrivingRouteQuery axleNumber(String) / getAxleNumber() | 轴数 |
DrivingRouteQuery plate(String) / getPlate() | 车牌 |
DrivingRouteQuery energy(int) / getEnergy() | 能源类型,>0 生效 |
DrivingRouteQuery width(String) / getWidth() | 车宽 |
DrivingRouteQuery volume(int) / getVolume() | 体积,>0 生效 |
DrivingRouteQuery cc(int) / getCc() | 坐标系 |
DrivingRouteQuery waypoints(List<LatLonPoint>) / getWaypoints() | 途经点列表 |
TruckRouteQuery
com.sfmap.api.search.query.TruckRouteQuery(/opsdkapi/v2/middleService/carRoutePlan,POST JSON)。在 DrivingRouteQuery 全部参数之外增加以下货车专属参数(链式 setter):
| 方法签名 | 说明 |
|---|---|
TruckRouteQuery mload(double) / getMload() | 核定载重(吨) |
TruckRouteQuery size(String) / getSize() | 车长(米) |
TruckRouteQuery axleWeight(String) / getAxleWeight() | 轴重 |
TruckRouteQuery sitNum(int) / getSitNum() | 座位数 |
TruckRouteQuery plateColor(int) / getPlateColor() | 车牌颜色,>0 生效 |
TruckRouteQuery emitStand(String) / getEmitStand() | 排放标准 |
TruckRouteQuery passport(String) / getPassport() | 通行证 |
TruckRouteQuery tolls(int) / getTolls() | 1 返回路桥费;建议同时传齐 weight/size/axleNumber |
TruckRouteQuery vlimit(String) / getVlimit() | 限速 |
TruckRouteQuery pathCount(int) / getPathCount() | 返回方案数,>0 生效 |
TruckRouteQuery planDate(String) / getPlanDate() | 规划日期 |
BikeRouteQuery
com.sfmap.api.search.query.BikeRouteQuery(/opsdkapi/v2/middleService/bikeRoutePlan,POST JSON)
| 方法签名 | 说明 |
|---|---|
BikeRouteQuery(LatLonPoint origin, LatLonPoint destination) | 坐标起终点(必填,不支持地址文本) |
static final int RIDING_TYPE_BIKE | 1,自行车(默认) |
static final int RIDING_TYPE_EBIKE | 2,电动车 |
BikeRouteQuery ridingType(int) / getRidingType() | 骑行类型 |
BikeRouteQuery opt(String) / getOpt() | 算法选项,默认 "2" |
WalkRouteQuery
com.sfmap.api.search.query.WalkRouteQuery(同骑行端点,travelType 固定 3)
| 方法签名 | 说明 |
|---|---|
WalkRouteQuery(LatLonPoint origin, LatLonPoint destination) | 坐标起终点(必填) |
WalkRouteQuery opt(String) / getOpt() | 算法选项,默认 "2" |
行政区划参数
DistrictQuery
com.sfmap.api.search.query.DistrictQuery(/opsdkapi/v2/getCityInfo,GET)
| 方法签名 | 说明 |
|---|---|
DistrictQuery(String adarea) | 行政区名称或 adcode(必填) |
static final int SUB_LEVEL_NONE / SUB_LEVEL_SHOW | 0 不含下级(默认)/ 1 含下级 |
DistrictQuery showSubLevel(int) / getShowSubLevel() | 是否返回下级列表 |
DistrictQuery extensions(int) / getExtensions() | 0 返回边界(默认)/ 1 不返回边界;仅省/市/区级别支持边界,街道/社区暂不支持 |
结果模型
以下模型均为标准 POJO(Serializable),getter/setter 成对提供,下表仅列 getter。
Tip(输入提示项)
com.sfmap.api.search.model.Tip。无坐标,需要坐标时需二次调用地理编码。
| 方法签名 | 说明 |
|---|---|
String getUid() | 唯一标识 |
String getName() | 名称 |
String getAddress() | 地址 |
String getAdcode() | 行政区编码 |
Poi(地址搜索项)
com.sfmap.api.search.model.Poi
| 方法签名 | 说明 |
|---|---|
String getUid() | 唯一标识 |
String getName() | 名称 |
String getAddress() | 地址 |
String getAdcode() / getCityadcode() | 行政区编码 / 城市编码 |
String getTypeName() | POI 分类名 |
String getExttype() | 扩展分类 |
LatLonPoint getLocation() | 坐标 |
GeocodeResult(地理编码结果)
com.sfmap.api.search.model.GeocodeResult
| 方法签名 | 说明 |
|---|---|
LatLonPoint getLocation() | 编码结果坐标 |
String getProvince() / getCity() / getDistrict() | 省 / 市 / 区 |
String getAdcode() | 行政区编码 |
String getGeoLevel() / getGeoLevelDesc() | 匹配级别编码 / 中文描述 |
String getMark() / getMarkDesc() | 精度标记编码 / 中文描述 |
String getSrcAddress() | 原始输入地址 |
String getSrc() / getType() | 数据源 / 类型 |
ReGeocodeResult(逆地理编码结果)
com.sfmap.api.search.model.ReGeocodeResult
| 方法签名 | 说明 |
|---|---|
String getName() | 位置描述 |
String getAoi() | 所属 AOI |
LatLonPoint getLocation() | 坐标 |
String getProvince() / getCity() / getDistrict() / getTown() | 省 / 市 / 区 / 街道 |
String getRoad() / getStreetNo() | 道路 / 门牌号 |
String getAdcode() / getRegcode() / getProvinceCode() | 区县 / 街道 / 省编码 |
List<ReGeocodePoi> getPoiList() | 周边 POI 列表 |
List<?> getAoiList() | 周边 AOI 列表(原始结构) |
ReGeocodePoi(逆地理 POI 项)
com.sfmap.api.search.model.ReGeocodePoi
| 方法签名 | 说明 |
|---|---|
String getName() | 名称 |
String getType() | 分类 |
double getDistance() | 距离(米) |
String getDirection() | 方位 |
LatLonPoint getLocation() | 坐标 |
String getAdcode() | 行政区编码 |
DrivingRouteResult(车行 / 货车规划结果)
com.sfmap.api.search.model.DrivingRouteResult
| 方法签名 | 说明 |
|---|---|
double getDist() | 距离(米) |
double getTime() | 耗时(秒) |
double getTolls() | 路桥费(元) |
double getTollsDistance() | 收费路段里程(米) |
double getHighway() | 高速里程(米) |
int getTraLightCount() | 红绿灯数 |
String getPolyline() | 路线折线(";" 分隔的 lng,lat 文本) |
List<RouteStep> getSteps() | 分路段导航指令 |
LatLonPoint getStartLocation() / getEndLocation() | 起 / 终点坐标 |
List<?> getWayPointList() | 途经段信息(货车高阶接口) |
List<?> getVoiRule() | 闯禁行信息(货车高阶接口) |
String getSrc() | 数据源 |
double getFlen() / getTlen() | 免费 / 收费里程 |
BikeRouteResult(骑行 / 步行规划结果)
com.sfmap.api.search.model.BikeRouteResult
| 方法签名 | 说明 |
|---|---|
List<RoutePath> getPaths() | 路径列表 |
LatLonPoint getOrigin() / getDestination() | 起 / 终点坐标 |
RoutePath(单条路径)
com.sfmap.api.search.model.RoutePath
| 方法签名 | 说明 |
|---|---|
double getDistance() | 距离(米) |
double getDuration() | 耗时(秒) |
String getPolyline() | 折线(";" 分隔的 lng,lat 文本) |
List<RouteStep> getSteps() | 分路段导航指令 |
int getTrafficlightCount() | 红绿灯数 |
LatLonPoint getOrigin() / getDestination() | 起 / 终点坐标 |
List<?> getViaPoints() | 途经点(原始结构) |
double getFlen() / getTlen() | 免费 / 收费里程 |
RouteStep(导航步骤)
com.sfmap.api.search.model.RouteStep(车行 / 骑行 steps 通用)
| 方法签名 | 说明 |
|---|---|
String getInstruction() | 指令文本 |
String getDirection() | 方向 |
String getRoad() | 道路名 |
int getDistance() | 本段距离(米) |
int getDuration() | 本段耗时(秒) |
String getAction() | 主要动作 |
String getAssistantAction() | 辅助动作 |
DistrictResult(行政区划结果)
com.sfmap.api.search.model.DistrictResult
| 方法签名 | 说明 |
|---|---|
List<DistrictItem> getDistricts() | 行政区划项列表 |
int getTotal() | 总数 |
DistrictItem(行政区划项)
com.sfmap.api.search.model.DistrictItem。省 / 市 / 区级别含边界几何,街道 / 社区暂不支持。
| 方法签名 | 说明 |
|---|---|
String getName() / getAdcode() | 名称 / 编码 |
String getLevel() | 级别常量:LEVEL_PROVINCE("1") / LEVEL_CITY("2") / LEVEL_DISTRICT("3") |
String getLevelName() | 级别中文名 |
LatLonPoint getCenter() | 中心点 |
String getGeometry() | WKT 边界原文(extensions=0 时携带) |
List<DistrictPolygon> getPolygons() | 边界多边形(外环 + 洞) |
List<String> getPolylines() | 边界环(";" 分隔的 lng,lat 文本,下级项携带) |
int getSubDistrictNum() | 下级数量 |
List<DistrictItem> getSubDistricts() | 下级列表(showSubLevel=1 时) |
DistrictPolygon(边界多边形)
com.sfmap.api.search.model.DistrictPolygon
| 方法签名 | 说明 |
|---|---|
String getOuterPolyline() | 外环边界(";" 分隔的 lng,lat 文本) |
List<String> getHolePolylines() | 内环洞列表(格式同外环) |
