一砌庄、使用高德地圖3D sdk 只需要在MAMapViewDelegate下面這個代理方法中改變centerAnnotation的坐標即可。(該方法在2D sdk中沒有)
func mapViewRegionChanged(mapView:MAMapView!) {
centerAnnotation?.coordinate= mapView.centerCoordinate
}
二志鹃、在高德2D sdk中的實現(xiàn)方法:
1.創(chuàng)建一個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當?shù)貓D的區(qū)域?qū)⒁l(fā)生改變時,顯示第一步創(chuàng)建的大頭針圖片,并刪除當前地圖上的Annotation(在2.2中會創(chuàng)建)
func mapView(mapView:MAMapView!, regionWillChangeAnimated animated:Bool) {
centerImageView.hidden=false
mapView.removeAnnotation(centerAnnotation)
}
2.2當?shù)貓D區(qū)域改變之后泽西,隱藏第一步創(chuàng)建的大頭針圖片曹铃,并且在當前地圖的中心點創(chuàng)建一個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
}