MKMapitem Placemark.name when creating MKMapItem from MKPlacemark

MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithPlacemark:mapItem1.placemark];

MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark1];

NSLog(@"placemark1.name is - %@", placemark1.name)

      

placemark1.name - - Starbucks

NSLog(@"mapItem1 placemark.name is - %@", mapItem1.placemark.name) 

      

mapItem1 placemark.name - - Starbucks

NSLog(@"item placemark.name is - %@", item.placemark.name) 

      

item placemark.name is - nil

mapItem1 has the correct value. mapItem1.placemark.name is "Startbucks".

When I implement as above item.placemark.name is zero. But placemark1.name is @ "Sartbucks".

When I made MKMapItem a different MKPlacemark it also puts mark.name on this MKMapItem, it is nil.

I don't know why this result came back.

I think the same value of the original label needs to be returned.

+3


source to share


2 answers


I notice that if you name the MapItem, the label will show the name.



extension MKPlacemark {
    var toMapItem: MKMapItem {
        let item = MKMapItem.init(placemark: self)
        item.name = name
        return item
    }
}

      

+3


source


I'm assuming mapItem1 is of type MKMapItem ? If so, you don't need to initialize a new MKPlacemark ( * placemark1 ), and you don't need to store placemark1 in a new MKMapItem ( * item ).

Since you are calling the label on mapItem1 in your code (mapItem1.placemark), I think I am correct in assuming it is of type MKMapItem.

To summarize, you don't need these lines of code:



MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithPlacemark:mapItem1.placemark];

MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark1];

      

Your MKMapItem * mapItem1 will work as is. Does this make sense? You kind of reinvent the wheel here. Just use mapItem1.placemark wherever you need to use it. I was working on a project that uses mapkit, so if you have any questions I would be happy to answer them.

0


source







All Articles