1. 7.丰富地图代理
1.1.1. 十三、丰富地图代理
第1步:修改地图代理协议
public protocol MapViewDelegateProtocol: NSObjectProtocol {
......
func mapView(_ mapView: MapViewProtocol, regionWillChangeAnimated animated: Bool)
func mapView(_ mapView: MapViewProtocol, regionDidChangeAnimated animated: Bool, wasUserAction: Bool)
func mapView(_ mapView: MapViewProtocol, didUpdate userLocation: UserLocationProtocol, updatingLocation: Bool)
}
第2步:修改地图代理实现
高德地图
class MAMapViewDelegateImpl: NSObject, MAMapViewDelegate {
......
func mapView(_ mapView: MAMapView!, regionWillChangeAnimated animated: Bool) {
delegate?.mapView(mapViewProtocol, regionWillChangeAnimated: animated)
}
func mapView(_ mapView: MAMapView!, regionDidChangeAnimated animated: Bool, wasUserAction: Bool) {
delegate?.mapView(mapViewProtocol, regionDidChangeAnimated: animated, wasUserAction: wasUserAction)
}
func mapView(_ mapView: MAMapView!, didUpdate userLocation: MAUserLocation!, updatingLocation: Bool) {
let gaodeUserLocation = GaodeUserLocation()
gaodeUserLocation.location = userLocation.location
gaodeUserLocation.heading = userLocation.heading
gaodeUserLocation.updating = userLocation.isUpdating
delegate?.mapView(mapViewProtocol, didUpdate: gaodeUserLocation, updatingLocation: updatingLocation)
}
}
百度地图
class BMKMapViewDelegateImpl: NSObject, BMKMapViewDelegate {
......
func mapView(_ mapView: BMKMapView!, regionWillChangeAnimated animated: Bool) {
delegate?.mapView(mapViewProtocol, regionWillChangeAnimated: animated)
}
func mapView(_ mapView: BMKMapView!, regionDidChangeAnimated animated: Bool, reason: BMKRegionChangeReason) {
let wasUserAction = reason == BMKRegionChangeReasonGesture
delegate?.mapView(mapViewProtocol, regionDidChangeAnimated: animated, wasUserAction: wasUserAction)
}
}