在MKMapView上更新用户位置的图像

时间:2015-12-16 14:46:35

标签: swift mkmapview mapkit mkannotationview

我在地图上为用户位置设置自定义图像,如下所示:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if annotation.isEqual(mapView.userLocation) {

        let identifier = "User"

        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)

        if annotationView == nil{
            annotationView = CustomPointAnnotation(annotation: annotation, reuseIdentifier: identifier)
            annotationView!.canShowCallout = true

        } else {
            annotationView!.annotation = annotation
        }

        annotationView!.image = UIImage(named: userImage)

        return annotationView

    }
    return nil
}

我已经更改了图像属性,如何告诉地图更新MKAnnotationView?

3 个答案:

答案 0 :(得分:0)

我认为你想要删除注释然后重新添加它们,这将迫使地图更新。直接编辑现有注释不会强制重绘地图。

答案 1 :(得分:0)

此解决方案适合我:

let userLocation = mapView.view(for: mapView.userLocation)
userLocation?.image = UIImage(named: "newImage")
userLocation?.isHidden = true
userLocation?.isHidden = false

答案 2 :(得分:0)

我的答案之一-https://stackoverflow.com/a/57868438/7505665

我有类似的问题,我的情况下的解决方案是这段代码

import multiprocessing
import numpy as np
import pandas pd

size = 100000
cols = list('abcdefghijklmnopqrstuvwxyz')
n_core = muliprocessing.cpu_count()

def format_col(col):
    return col, ["%s_%d" % (col, n) for n in np.arange(size)]

with multiprocessing.Pool(n_core) as pool:
    result = {}
    for res in pool.map(format_col, cols):
        result[res[0]]=res[1]
        result.extend(res)
df = pd.DataFrame(result)