-1

I am working on location based application in which i need to move MKAnnotation Pin as per the change location. It means as user change location from once place to other the Annotation should be moved.

This is my code of annotation:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *defaultPinID = @"com.invasivecode.pin";
    pinView = (MKPinAnnotationView *)[mV dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if (pinView == nil)
    {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
        pinView.enabled = YES;
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.canShowCallout = YES;
    }
    return pinView;
}

It drops the pin on the current location but when i move with device the location changed & also MKPolyline i have implement but Pin stays there.

see this image : enter image description here

You can see in this the green pin is the start point & the other side is the current point. So the pin should be on the current point thats what i want.

I have searched & tried few of the solutions of stack but not able to solve my issue.

Any suggestions & help will be highly appreciated.

Thanks in advance.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
  • 1
    What solutions have you tried? Have you tried this one: http://stackoverflow.com/questions/11432746/custom-annotation-view-for-userlocation-not-moving-the-mapview –  Jul 01 '13 at 12:59
  • @AnnaKarenina did that but still Annotation is unmoved – Mayur Prajapati Jul 01 '13 at 13:02
  • 1
    You should post the code you tried. The picture is not needed. –  Jul 01 '13 at 13:04
  • @AnnaKarenina yes i already posted my code but i wanted to show i exactly i am getting outcome for quick understanding. – Mayur Prajapati Jul 01 '13 at 13:12
  • 1
    The code in viewForAnnotation only determines how the annotation will appear (it doesn't make it "move"). Show the code where you change the annotation's coordinates as suggested in the linked answer. –  Jul 01 '13 at 13:17
  • @AnnaKarenina thanks your suggestion helped me to solve out my problem thank you so much. – Mayur Prajapati Jul 01 '13 at 13:36

1 Answers1

0

I got the solution from @AnnaKarenina suggestions thank you so much.

What i have done is make my MKPinAnnotationView global & then :

pinView.annotation.coordinate = newLocation.coordinate;

This line i added into didUpdateToLocation method which allows annotation to get new location every time.

Thanks again.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
  • 1
    Technically, the linked answer suggests to keep a reference to the _id_ object which is the one you pass to addAnnotation (not the _MKAnnotationView_). Keeping a reference to the view may only work if you have just one annotation. –  Jul 01 '13 at 13:42