首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改MKMapView用户位置注释

更改MKMapView用户位置注释
EN

Stack Overflow用户
提问于 2016-04-28 06:55:35
回答 4查看 7.1K关注 0票数 5

我正在尝试将MKMapView上的用户默认位置注释从蓝色更改为名为geo的自定义图像。当我设置断点时,将其设置为geo就是命中线,但是这两个点(用户默认和乘客点都是默认的红色针点注释)是我设置错了吗,还是有特定的图像规定?

代码语言:javascript
运行
复制
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

        if annotation.isKindOfClass(PassengerLocation) == false {

            //User location
            let userIdentifier = "UserLocation"
            var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(userIdentifier)

            if annotationView == nil {
                annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:userIdentifier)
            }
            annotationView!.annotation = annotation
            annotationView!.canShowCallout = true

            // THIS IS NOT WORKING, DEFAULT RED PIN POINT STILL SHOWING
            annotationView!.image = UIImage(named: "geo")
            return annotationView


        }

        let identifier = "PassengerLocation"

        if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) {
            annotationView.annotation = annotation

            return annotationView
        } else {
            let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:identifier)
            annotationView.enabled = true
            annotationView.canShowCallout = true

            let btn = UIButton(type: .DetailDisclosure)
            annotationView.rightCalloutAccessoryView = btn

            return annotationView
        }

    }
EN

回答 4

Stack Overflow用户

发布于 2016-05-03 13:54:19

这是可行的:

代码语言:javascript
运行
复制
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
        if annotation.isEqual(mapView.userLocation) {
        let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "userLocation")
        annotationView.image = UIImage(named: "geo")
        return annotationView
    }
}
票数 6
EN

Stack Overflow用户

发布于 2016-09-16 17:54:17

这对我很有效

代码语言:javascript
运行
复制
    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    // want to show a custom image if the annotation is the user's location.
    guard !annotation.isKindOfClass(MKUserLocation) else {
        let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "userLocation")
        annotationView.image = UIImage(named: "icon_coordinates_self")
        return annotationView
        //return nil
    }

    let annotationIdentifier = "AnnotationIdentifier"

    var annotationView: MKAnnotationView?
    if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) {
        annotationView = dequeuedAnnotationView
        annotationView?.annotation = annotation
    }
    else {
        let av = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
        av.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure)
        annotationView = av
    }

    if let annotationView = annotationView {
        // Configure your annotation view here
        annotationView.canShowCallout = true
        annotationView.image = UIImage(named: "Annotation_map")
    }

    return annotationView
}
票数 2
EN

Stack Overflow用户

发布于 2016-04-28 07:24:04

如果要自定义镜像,请使用常规MKAnnotationView。用大头针,你所能做的就是改变颜色。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36902363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档