您需要实现
viewForAnnotation委托方法并
MKAnnotationView从那里返回。
这是一个例子:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if (annotation is MKUserLocation) { //if annotation is not an MKPointAnnotation (eg. MKUserLocation), //return nil so map draws default view for it (eg. blue dot)... return nil } let reuseId = "test" var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) if anView == nil { anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) anView.image = UIImage(named:"xaxas") anView.canShowCallout = true } else { //we are re-using a view, update its annotation reference... anView.annotation = annotation } return anView}请记住,当您要使用自己的自定义图像时,需要创建一个 普通
MKAnnotationView图像。本
MKPinAnnotationView应只用于标准引脚注解。
另请注意,您不应
locationManager.location在致电后立即尝试访问
startUpdatingLocation。可能尚未准备好。
使用
didUpdateLocations委托方法。
您还需要致电
requestAlwaysAuthorization/
requestWhenInUseAuthorization



