gpt4 book ai didi

swift - 从 PFGeoPoint 中获取纬度/经度

转载 作者:行者123 更新时间:2023-11-28 12:41:34 25 4
gpt4 key购买 nike

我目前在 Parse Server 上有一个 PFGeoPoint,我可以通过执行以下操作(在 Swift 中)成功检索它:

let geo = listingObject?.objectForKey("geo")
// <PFGeoPoint: 0x7ff37d184840, latitude: 51.510005, longitude: -0.128493>

我现在想做的是将其中的纬度和经度放入它们自己的变量中。

当我创建 map 注释时,例如以下工作:

let anno = mapAnnotation(coordinate: CLLocationCoordinate2D(latitude: (geo?.latitude)!, longitude: (geo?.longitude)!))

但是这会产生错误:

let latitude = geo?.latitude
// Ambiguous use of 'latitude'

谁能指出我正确的方向?

最佳答案

objectForKey 返回AnyObject,编译器不知道类型是PFGeoPoint。解决方案是将值转换为正确的类型。

当使用可选绑定(bind)时,你可以去掉所有的 ?! 标记

if let geo = listingObject?.objectForKey("geo") as? PFGeoPoint {
let anno = mapAnnotation(coordinate: CLLocationCoordinate2D(latitude: geo.latitude, longitude: geo.longitude)
}

关于swift - 从 PFGeoPoint 中获取纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39315501/

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