Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hi all,

I'm using MKMapView, and drawing polylines for routes.
Now I want to pull coordinates from an external API where I only get latitude and longitude based on provided 'ID'.

I'm adding pins like :
Code:
CLLocationCoordinate2D tCoord = CLLocationCoordinate2DMake(latitude,longitude);
 
    MKPointAnnotation *tPin = [[MKPointAnnotation alloc] init];
    CLLocationCoordinate2D pinCoords = tCoord;
    [tPin setCoordinate: pinCoords];
    [tPin setTitle: [NSString stringWithFormat: @"%@", teamID]];
    [mapper addAnnotation: tPin];

How can I update this specific pin ? i.e. 5 minutes later, without clearing all pins and duplicating this pin, but on other location. (preventing trails of pins from the team's route)
 
Hi all,

I'm using MKMapView, and drawing polylines for routes.
Now I want to pull coordinates from an external API where I only get latitude and longitude based on provided 'ID'.

I'm adding pins like :
Code:
CLLocationCoordinate2D tCoord = CLLocationCoordinate2DMake(latitude,longitude);
  
    MKPointAnnotation *tPin = [[MKPointAnnotation alloc] init];
    CLLocationCoordinate2D pinCoords = tCoord;
    [tPin setCoordinate: pinCoords];
    [tPin setTitle: [NSString stringWithFormat: @"%@", teamID]];
    [mapper addAnnotation: tPin];

How can I update this specific pin ? i.e. 5 minutes later, without clearing all pins and duplicating this pin, but on other location. (preventing trails of pins from the team's route)[/code]

You should be able to call setCoordinate on the MKPointAnnotation again. Does that not work?
 
  • Like
Reactions: DennisBlah
You should be able to call setCoordinate on the MKPointAnnotation again. Does that not work?
Hi Krevnik,

thanks very much for your fast reply! :eek:
How would I do this ? I'm can't set a 'tag' on my MKPointAnnotation.
Or should I init a 'global' MKPointAnnonation for each team on my viewcontroller ? I'll give this at try.
/\
Yes that works! It's going to be anoying when refreshing my main 'route' as it clears all.
Any way how I can 'mark' this annonation, so it won't be deleted?
 
Your code creates an Annotation and adds it to mapper, which I assume is linked to the MKMapView or is the map view.

You need to keep a reference to that Annotation and update it when your model changes. Depending on how your model works, you could make a controller class that holds a reference to the Annotation and the object that represents, updating one when the other changes.
 
Your code creates an Annotation and adds it to mapper, which I assume is linked to the MKMapView or is the map view.

You need to keep a reference to that Annotation and update it when your model changes. Depending on how your model works, you could make a controller class that holds a reference to the Annotation and the object that represents, updating one when the other changes.

Now when I reset the map (removing all annotation's and polylines) I'm adding this 'global' initiated pin again to the map.
All other PIN's are dynamic.

I'm not working with actual models on xcode yet.
Thanks for your help! I don't know why I didn't think of it earlier :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.