Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

convert NSArray to MKPlacemark

dickthedevdickthedev Posts: 183Registered Users @ @
Hello, I have a forward geocode block. like this:

[_geoCoder geocodeAddressString:searchString completionHandler:^(NSArray *placemarks, NSError *error) {
....
}];

As is, the geocode data stores in the NSArray *placemarks. Now I would like to do some annotation to the map, The addAnnotation method requires a MKPlacemark, so how do I convert the place mark in NSArray into a MKPlacemark? Thanks.

Replies

  • Duncan CDuncan C Posts: 9,112Tutorial Authors, Registered Users @ @ @ @ @ @ @
    You already asked this and dev666999 answered you. (For converting a single CLPlacemark to an MKPlacemark.

    If you create a function that takes a CLPlacemark as input and returns an MKPlacemark then you could use a map function to convert an array of CLPlacemark objects to MKPlacemark objects.

    Taking it a step further, you could create an extension to MKPlacemark that defines a convenience initializer that takes a CKPlacemark as input.
    extension MKPlacemark {
      convenience init(withCLPlacemark: CLPlacemark) {
          //code from other answer to set up place mark
      }
    }
    

    And then:
    Let anMKPlacemarkArray = aCLPlacemarkArray.map{MKPlacemark.init(withCLPlacemark($0)}
    
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.