0

I have added the following code and not able to see any pin changes with new image and no error is getting displayed. map.delegate = self is done. do we need to add any code to make it work? any help?

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
}

1 Answer 1

1

I am not sure whether you have already set the delegate for your mapView in viewDidLoad method. If not please do it. Because setting it inside viewForAnnotation will never call this delegate method. Move routeMapView.delegate = self from viewForAnnotation to viewDidLoad method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.