gpt4 book ai didi

ios - 使用 Xcode 7 Swift2 更改 MKMapView 上的图钉图像

转载 作者:行者123 更新时间:2023-11-29 01:50:05 24 4
gpt4 key购买 nike

我添加了以下代码,但无法看到新图像的任何引脚更改,并且没有显示错误。 map.delegate = self 已完成。我们需要添加任何代码才能使其工作吗?有帮助吗?

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
let region:MKCoordinateRegion = MKCoordinateRegionMake(userLocation.coordinate, span)


routeMapView.setRegion(region, animated: true)

currentLocationAnnotation.coordinate = userLocation.coordinate
mapView(routeMapView, viewForAnnotation: currentLocationAnnotation)!.annotation = currentLocationAnnotation
routeMapView.addAnnotation(currentLocationAnnotation)
//print("getting current location..")
getCurrentLocationAddress(userLocation)

userCurrentLocation = userLocation
userLocationSpan = span
counter++

}


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

if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}

let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.image = UIImage(named:"first")!
print(pinView!.image!)
routeMapView.delegate = self
}
else {
pinView!.annotation = annotation
}

return pinView
}

最佳答案

我不确定您是否已经在 viewDidLoad 方法中为您的 mapView 设置了委托(delegate)。如果没有,请这样做。因为在 viewForAnnotation 中设置它永远不会调用这个委托(delegate)方法。将 routeMapView.delegate = self 从 viewForAnnotation 移动到 viewDidLoad 方法。

关于ios - 使用 Xcode 7 Swift2 更改 MKMapView 上的图钉图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31507776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com