一、使用高德地图3D sdk 只需要在MAMapViewDelegate下面这个代理方法中改变centerAnnotation的坐标即可。(该方法在2D sdk中没有)
func mapViewRegionChanged(mapView:MAMapView!) {
centerAnnotation?.coordinate= mapView.centerCoordinate
}
二、在高德2D sdk中的实现方法:
1.创建一个UIImageView 添加到view的中心:
private lazy var centerImageView:UIImageView= {
let centerImageView =UIImageView.init(image:UIImage.init(named:"mg_redPin_lift"))
return centerImageView
}()
view.addSubview(centerImageView)
centerImageView.snp_makeConstraints{ (make)in
make.center.equalTo(self.view)
}
2.在MAMapViewDelegate的代理方法中
2.1当地图的区域将要发生改变时,显示第一步创建的大头针图片,并删除当前地图上的Annotation(在2.2中会创建)
func mapView(mapView:MAMapView!, regionWillChangeAnimated animated:Bool) {
centerImageView.hidden=false
mapView.removeAnnotation(centerAnnotation)
}
2.2当地图区域改变之后,隐藏第一步创建的大头针图片,并且在当前地图的中心点创建一个Annotation
func mapView(mapView:MAMapView!, regionDidChangeAnimated animated:Bool) {
if !centerImageView.hidden {
centerImageView.hidden=true
if(centerAnnotation==nil){
let pointAnnotation =MAPointAnnotation()
centerAnnotation= pointAnnotation
pointAnnotation.coordinate= mapView.centerCoordinate
pointAnnotation.title="东方明珠"
pointAnnotation.subtitle="东方明珠1号"
mapView.addAnnotation(pointAnnotation)
}
centerAnnotation?.coordinate= mapView.centerCoordinate
}