ios - Mapview - protection against coordinates found nil -
i have mapview downloads records off cloudkit. coordinates of each record based on forward geocoder, users add address (ex: new york, ny) , lats , lons obtained
current model follow:
class place: nsobject { var name: string var address: string var comment: string? var photo: uiimage? var rating: int var location: cllocation? var identifier: string var record: ckrecord! init(record: ckrecord) { self.record = record self.name = record.valueforkey(placename) as! string self.address = record.valueforkey(placeaddress) as! string self.comment = record.valueforkey(placecomment) as? string if let photoasset = record.valueforkey(placephoto) as? ckasset { self.photo = uiimage(data: nsdata(contentsofurl: photoasset.fileurl)!) } self.rating = record.valueforkey(placerating) as! int self.location = record.valueforkey(placelocation) as? cllocation self.identifier = record.recordid.recordname } // mark: map annotation var coordinate: cllocationcoordinate2d { { return location!.coordinate } }
this method place each pin on mapview.
func placepins() { place: place in self.places { let location = cllocationcoordinate2dmake(place.coordinate.latitude, place.coordinate.longitude) let droppin = custompointannotation(place: place) droppin.pincustomimagename = "custompin" droppin.coordinate = location droppin.title = place.title droppin.subtitle = place.subtitle droppin.name = place.name droppin.image = place.photo mapview.addannotation(droppin) } }
how fix them protect against record doesn't have coordinates since forward geocoder not reliable way?
what about
for place: place in self.places { if (place.location == nil) { continue; } ... }
not sure issue there
Comments
Post a Comment