Appearance
定位
LocationSource
包名:com.sfmap.api.maps
定位资源接口,用于外部注入定位数据。接入方实现该接口后,由 SDK 在需要时调用 activate 激活定位,并在拿到定位结果后通过回调 OnLocationChangedListener 将定位数据回传给地图。
内部回调接口
OnLocationChangedListener
包名:com.sfmap.api.maps.LocationSource.OnLocationChangedListener
定位变化监听器,由 SDK 在激活定位时传入。接入方获取到定位结果后,调用该回调将定位数据回传给地图。
| 返回类型 | 方法名(参数) | 说明 |
|---|---|---|
| void | onLocationChanged(Location location) | 定位发生变化时回调,将最新的定位数据传入地图 |
接口方法
| 返回类型 | 方法名(参数) | 说明 |
|---|---|---|
| void | activate(OnLocationChangedListener listener) | 激活定位。SDK 传入定位变化监听器,接入方拿到定位结果后通过该监听器回调 |
| void | deactivate() | 停止定位。SDK 不再需要定位数据时调用,接入方应在此释放定位资源 |
MyLocationStyle
包名:com.sfmap.api.maps.model
定位小蓝点(我的位置)样式,实现 Parcelable。通过链式方法配置定位图标的锚点、填充色、边框、定位类型、刷新间隔等样式,再设置给地图。
常量
定位类型
| 常量名 | 值 | 说明 |
|---|---|---|
| LOCATION_TYPE_LOCATE | 1 | 定位模式:仅定位一次,地图不跟随/旋转 |
| LOCATION_TYPE_MAP_FOLLOW | 2 | 定位模式:地图跟随我的位置移动 |
字段默认值
| 字段 | 默认值 | 说明 |
|---|---|---|
| anchorU | 0.5f | 锚点横向归一化坐标,0.5 表示水平居中 |
| anchorV | 1.0f | 锚点纵向归一化坐标,1.0 表示底部对齐 |
| radiusFillColor | 0 | 精度圆填充色 |
| strokeColor | 0 | 精度圆边框色 |
| strokeWidth | 1.0f | 精度圆边框宽度 |
| myLocationType | LOCATION_TYPE_LOCATE (1) | 定位类型 |
| interval | 2000 | 定位刷新间隔(毫秒) |
| showMyLocation | true | 是否显示定位小蓝点 |
链式方法
以下方法均返回 MyLocationStyle,支持链式调用。
| 返回类型 | 方法名(参数) | 说明 |
|---|---|---|
| MyLocationStyle | myLocationIcon(BitmapDescriptor myLocationIcon) | 设置定位图标 |
| MyLocationStyle | icon(BitmapDescriptor icon) | 设置定位图标,等同于 myLocationIcon(icon) |
| MyLocationStyle | anchor(float u, float v) | 设置定位图标锚点,u/v 为归一化坐标(0~1),默认 (0.5, 1.0) 即水平居中、底部对齐 |
| MyLocationStyle | radiusFillColor(int color) | 设置精度圆(定位光晕)的填充色 |
| MyLocationStyle | strokeColor(int color) | 设置精度圆边框颜色 |
| MyLocationStyle | strokeWidth(float width) | 设置精度圆边框宽度 |
| MyLocationStyle | myLocationType(int type) | 设置定位类型,取值为 LOCATION_TYPE_LOCATE、LOCATION_TYPE_MAP_FOLLOW |
| MyLocationStyle | interval(int interval) | 设置定位刷新间隔(毫秒),默认 2000 |
| MyLocationStyle | showMyLocation(boolean show) | 设置是否显示定位小蓝点 |
Getter 方法
| 返回类型 | 方法名(参数) | 说明 |
|---|---|---|
| BitmapDescriptor | getMyLocationIcon() | 获取定位图标 |
| float | getAnchorU() | 获取锚点横向归一化坐标 |
| float | getAnchorV() | 获取锚点纵向归一化坐标 |
| int | getRadiusFillColor() | 获取精度圆填充色 |
| int | getStrokeColor() | 获取精度圆边框色 |
| float | getStrokeWidth() | 获取精度圆边框宽度 |
| int | getMyLocationType() | 获取定位类型 |
| int | getInterval() | 获取定位刷新间隔(毫秒) |
| boolean | isShowMyLocation() | 是否显示定位小蓝点 |
Parcelable 方法
| 返回类型 | 方法名(参数) | 说明 |
|---|---|---|
| int | describeContents() | Parcelable 接口实现,返回 0 |
| void | writeToParcel(Parcel parcel, int flags) | 序列化到 Parcel。仅写入基础字段(anchorU、anchorV、radiusFillColor、strokeColor、strokeWidth),不写入 BitmapDescriptor(其非 Parcelable) |
