gpt4 book ai didi

ios - Mapview - 防止发现坐标为零

转载 作者:行者123 更新时间:2023-11-29 01:15:36 25 4
gpt4 key购买 nike

我有 mapview 从 CloudKit 下载记录。每条记录的坐标基于正向地理编码器,用户在其中添加地址(例如:纽约,纽约州)并获得纬度和经度

当前模型如下:

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 {
get {
return location!.coordinate
}
}

这是我将每个图钉放置在 map View 上的方法。

func placePins()
{
for 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)

}
}

由于前向地理编码器不是最可靠的方法,我该如何修复它们以防止任何没有坐标的记录?

最佳答案

关于

for place: Place in self.places
{
if (place.location == nil) {
continue;
}
...
}

不知道是什么问题

关于ios - Mapview - 防止发现坐标为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35227163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com