Appearance
SFMapSearchSDK API
#import <SFMapSearchSDK/SFMapSearchKit.h>
搜索服务 API。单例 SFMSearchAPI.sharedAPI 统一入口,8 个在线搜索接口 + 任务清理,统一 SFMSearchCallbackBlock block 回调(主线程回调,可直接更新 UI)。
配置项集中在 SFMSearchConfig 单例;请求/响应均为独立模型类(见文末)。
集成方式与 AK 配置见 搜索服务。
回调类型
objc
typedef void(^SFMSearchCallbackBlock)(id _Nullable response, NSError * _Nullable error);出错时 response == nil。错误约定:参数校验错误统一 code 101(domain 形如「参数校验错误,缺少必填参数[xx为空]」);服务端 status==1 取 result.msg;errorMessage 非空取之;direction v3 系列按 code != 200 判失败(取 msg)。
SFMSearchConfig
#import <SFMapSearchSDK/SFMSearchConfig.h>
+ (instancetype)sharedConfig; 单例。
| 属性 | 默认值 | 说明 |
|---|---|---|
searchUrlHost | https://gis-tx.sf-express.com | 服务基址。取值优先级:运行时覆盖 > Info.plist SFMapSearchServer > 默认。测试环境:http://ftkj-gis-apis.intsit.sfcloud.local:1080(direction v3 仅测试 host 提供) |
tipPath | /tip/api | 输入提示 |
geoPath | /geo/api | 地理编码(旧文档的 /geo/direct 仅测试 host 提供) |
rgeoPath | /rgeo/api | 逆地理编码 |
drivingPath | /rp/v2/api | 车行路径规划 |
tipbsPath | /tipbs/api | 大搜关键字 |
bikePath / motorPath / walkPath | /direction/v3/api/bike | motor | walk | 骑行(自行车/电动车)/步行 |
SFMSearchAPI
#import <SFMapSearchSDK/SFMSearchAPI.h>
+ (instancetype)sharedAPI; 单例。
地理编码
objc
- (void)sfmGeocodeSearch:(SFMGeocodeSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack;地址 → 坐标。POST JSON。必填 address。返回 SFMGeocodeSearchResponse。
逆地理编码
objc
- (void)sfmReGeocodeSearch:(SFMReGeocodeSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack;坐标 → 地址。GET。返回 SFMReGeocodeSearchResponse。
输入提示
objc
- (void)sfmInputTipsSearch:(SFMInputTipsSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack;GET。必填 q(长度>1)、city。返回 SFMInputTipsSearchResponse。
车行路径规划
objc
- (void)sfmDrivingRouteSearch:(SFMDrivingRouteSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack;GET,端点 /rp/v2/api。起终点坐标与地址四选二(坐标优先,x1/y1/x2/y2),支持途经点、规避区域、车辆约束(weight/height/axleNumber/plate/planDate)。返回 SFMRouteSearchResponse。
关键字搜索(大搜)
objc
- (void)sfmKeywordSearch:(SFMKeywordSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack;GET,端点 /tipbs/api。q 与 type_code 至少填一个。返回 SFMKeywordSearchResponse(含多城市建议列表)。
骑行 / 步行路径规划
objc
- (void)sfmBikeRouteSearch:(SFMDirectionRouteSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack; // 自行车
- (void)sfmMotorRouteSearch:(SFMDirectionRouteSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack; // 电动车
- (void)sfmWalkRouteSearch:(SFMDirectionRouteSearchRequest *)request callBack:(SFMSearchCallbackBlock)callBack; // 步行GET,direction v3。起终点三级优先级:坐标 > AOI(startAoi/endAoi)> 地址。返回 SFMDirectionRouteSearchResponse(响应结构为 {code:200, data},与其他接口不同)。
任务管理
objc
- (void)sfmCleanAllTask;取消并清理所有在途请求任务(页面退出时调用)。
请求模型(SFMSearchRequest.h)
SFMGeocodeSearchRequest
| 属性 | 类型 | 说明 |
|---|---|---|
address | NSString | 待解析地址,必填 |
city | NSString | 地址所在城市(中文名 / 755 等),选填 |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
SFMReGeocodeSearchRequest
| 属性 | 类型 | 说明 |
|---|---|---|
x / y | double | 经 / 纬度,必填 |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
fill | NSInteger | =1 补全省 / 直辖市 / 直筒子市缺失层级 |
addr_level | NSInteger | 地址拼接精度 1/2/3 |
bldnum | NSInteger | 返回楼栋列表数量,最多 20 |
SFMInputTipsSearchRequest
| 属性 | 类型 | 说明 |
|---|---|---|
q | NSString | 关键词,必填,长度 > 1 |
city | NSString | 对应城市,必填 |
district | NSString | 中文区县,需 city 非空 |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
la | NSString | adname 输出语言 chs / cht / en |
type | NSString | =detail 时过滤 ROADLINE / DISTRICT |
SFMDrivingRouteSearchRequest(继承 SFMRouteSearchBaseRequest)
基类属性:origin / destination(SFMGeoPoint,坐标)。
| 属性 | 类型 | 说明 |
|---|---|---|
originAddr / destinationAddr | NSString | 起 / 终点地址(与坐标四选一,坐标优先) |
strategy | NSInteger | 策略:0 时间优先(默认)等 |
opt | NSString | sf1/sf2/sf3/sf4,默认 sf2 |
type | NSInteger | 导航类型:0 驾车 |
vehicle | NSString | 车辆类型:1 小车(默认)等 |
weight / height | double | 车辆总重(吨)/ 高度(米),0 用默认 |
axleNumber | NSString | 车辆轴数,0 用默认 |
plate | NSString | 车牌号,如 粤B12345 |
planDate | NSString | 出行时间 yyyymmddHHMM |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
waypoints | NSArray<SFMGeoPoint> | 途经点 |
avoidpolygons | NSArray<SFMGeoPolygon> | 规避区域 |
SFMKeywordSearchRequest
| 属性 | 类型 | 说明 |
|---|---|---|
q | NSString | 关键词,长度 > 1;与 type_code 至少填一个 |
type_code | NSString | POI 类型编码(如金融机构 160000),多个用 | 分隔 |
city / district | NSString | 城市 / 中文区县(需 city 非空) |
search_region | NSInteger | 0 全国搜,1 指定城市搜(默认),2 全国宽松搜 |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
page_index / page_size | NSInteger | 页号(默认 1)/ 每页数量(默认 10),0 值不携带 |
SFMDirectionRouteSearchRequest(继承 SFMRouteSearchBaseRequest)
| 属性 | 类型 | 说明 |
|---|---|---|
opt | NSString | sf1~sf4,默认 sf2(距离时长 + 坐标点) |
stype / etype | NSString | 起 / 终点绑路类型:0 GPS 点,2 POI 点(默认) |
originAddr / destinationAddr | NSString | 起 / 终点地址(坐标 > AOI > 地址) |
startAoi / endAoi | NSString | 起点 / 终点 AOI |
startCity / endCity | NSString | 起终点省市区 "xx省|xx市|xx区" |
planDate | NSString | 出行时间 yyyymmddHHMM |
cc | NSInteger | 坐标系:1 高德(默认),2 百度 |
canPassFootBridge | NSInteger | 1 允许人行天桥,默认 0 |
waypoints | NSArray<SFMGeoPoint> | 途经点 |
响应模型(SFMSearchResponse.h)
| 类 | 关键属性 | 说明 |
|---|---|---|
SFMGeocodeSearchResponse | geocodes(SFMGeocode 数组) | 地理编码 |
SFMReGeocodeSearchResponse | count、regeocodes(SFMReGeocode 数组) | 逆地理 |
SFMInputTipsSearchResponse | count、tips(SFMTip 数组) | 输入提示 |
SFMKeywordSearchResponse | count(总数)、pois(SFMPOI 数组)、suggestions(SFMCitySuggestion 数组,多城市命中时) | 大搜 |
SFMRouteSearchResponse | type、info、route(SFMRoute) | 车行规划 |
SFMDirectionRouteSearchResponse | origin / destination(SFMGeoPoint)、paths(SFMPath 数组) | 骑行 / 步行规划 |
SFMCitySuggestion | adcode、name、regcode、total | 城市建议(大搜多城市命中时) |
通用数据结构(SFMSearchObject.h)
SFMGeoPoint / SFMGeoPolygon
objc
@property (nonatomic, assign) CGFloat latitude;
@property (nonatomic, assign) CGFloat longitude;
+ (SFMGeoPoint *)locationWithLatitude:(CGFloat)lat longitude:(CGFloat)lon;SFMGeoPolygon.points 为 SFMGeoPoint 数组;+polygonWithPoints: 构造。
SFMGeocode
| 属性 | 说明 |
|---|---|
province / city / district | 省 / 市 / 区(来自响应 adname) |
name | 原始地址(src_address) |
adcode | 行政区划码 |
location | 坐标(SFMGeoPoint) |
level | 匹配级别(响应 type) |
precise / confidence | 精确标志 / 置信度 |
SFMReGeocode / SFMAddressComponent
| 属性 | 说明 |
|---|---|
formattedAddress | 拼接地址 |
addressComponent | 省 / 市 / 区 / 街道 / 门牌号 / adcode / cityCode / distance |
location | 坐标 |
pois / recentlyPOI | 周边 POI 列表 / 最近 POI |
SFMPOI
常用字段:uid、guid、aoi_guid、name、sname、location、x / y、address、type、detail_type、exttype、pc_type、tel、datasource、distance、adcode、extinfo、deep_infos、company_infos。
辅助方法:-getValidUid、-isCompany、-isBuilding、-isCCB。
pc_type:1 大门入口 / 2 停车场 / 3 楼栋 / 4 公司 / 5 电梯 / 6 单元门。
exttype 类型宏:SF_EXT_TYPE_POI / AOI / CCB / PROVINCE / CITY / COUNTY / TOWN / ROADLINE / BUILDING / COMPANY。
SFMTip
| 属性 | 说明 |
|---|---|
uid / name / adcode / district / city / cityCode | 提示项基础信息 |
location / fromLocation | 坐标 |
type / exttype / extinfo / aoi_guid | 类型与扩展 |
address / tel / business / datasource | 地址 / 电话 / 商圈 / 数据源 |
deep_infos | 深度信息 |
- (SFMPOI *)translateToPOI; 转换为 POI 对象。
SFMRoute / SFMPath / SFMStep(车行)
| 类 | 关键属性 |
|---|---|
SFMRoute | origin / destination(SFMRoutGeoPoint)、taxi、trafficCondition、paths |
SFMPath | distance、duration、strategy、tolls、steps(SFMStep 数组)、polyline(整条路线坐标 "lng,lat;lng,lat;...")、originLocation / destinationLocation |
SFMStep | instruction、path、orientation、distance、duration、turn、type、stepOriginLocation / stepDestinationLocation |
