How to update MKAnnotation location with new coordinates?

I am having problems updating the location of the annotation with different coordinates. Is there a way to change the location property without creating another annotation? I tried the code below with no luck. The annotation I'm trying to get does not update its location. Please, help!

CLLocationCoordinate2D location;
location.latitude = -36.560976;
location.longitude = -59.455807; 

for (id annotation in self.mapView.annotations) {

    if ([annotation isKindOfClass:[MyAnnotation class]]) 
    {
            [annotation setCoords:location]; //setCoords is defined in MyAnnotation class
            }
    }

Thanks everyone!

+3
source share
4 answers

To expand MKPointAnnotation, it has the ability to automatically update the annotation on the map to new coordinates.

@interface MyAnnotation : MKPointAnnotation
+3
source

. MapKit , .

-1

, , .

MapView, , . , , , , , location, coordinate.

MKAnnotation , CLLocationCoordinate2D coordinate . .

Try adding the instance variable CLLocationCoordinate2D coordinateand its matching property @property (assign, nonatomic) CLLocationCoordinate2D coordinateto your annotation .h file. Then use @synthesizeannotations in your .m file.

If this does not solve your problem, you may need to add more details to your question.

-1
source

Source: https://habr.com/ru/post/1746658/


All Articles