gpt4 book ai didi

快速向前地理定位并访问地标经度和经度

转载 作者:行者123 更新时间:2023-11-30 13:55:29 24 4
gpt4 key购买 nike

我使用正向地理编码来获取事件的二维坐标。现在我试图获取事件地址的经度和纬度。我已成功创建一个包含坐标的地标,但我不知道如何将其从坐标更改为经度或纬度

有什么想法吗?

if let objects = objects {
for object in objects {

self.geocoder = CLGeocoder()

//get address from object
let COAddress = object.objectForKey("Address")as! String
let COCity = object.objectForKey("City")as! String
let COState = object.objectForKey("State")as! String
let COZipCode = object.objectForKey("ZipCode")as! String
let combinedAddress = "\(COAddress) \(COCity) \(COState) \(COZipCode)" //all parts of address
print(combinedAddress)

//make address a location

self.geocoder.geocodeAddressString(combinedAddress, completionHandler: {(placemarks, error) -> Void in

if(error != nil)
{

print("Error", error)
}

else if let placemark = placemarks?[0]
{

let placemark:CLPlacemark = placemarks![0]
var coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
print("i got here", coordinates)

}
})

let userLatitude = self.locationManager.location?.coordinate.latitude
let userLongitude = self.locationManager.location?.coordinate.longitude
let userLocation = CLLocation(latitude: userLatitude!, longitude: userLongitude!)

// event location - THE ERROR IS BELOW
let eventLatitude = placemarks.location?.cordinate.latitude
let eventLongitude = placemarks.location?.coordinate.longitude
let eventLocation = CLLocation(latitude: eventLatitude!, longitude: eventLongitude!)

//Measuring my distance to my buddy's (in km)

let distance = userLocation.distanceFromLocation(eventLocation) / 1000

//Display the result in km
print("The distance to event is ", distance)

if (distance < 100) {

print("yay")
}
}
}

最佳答案

// event location - THE ERROR IS BELOW
let eventLatitude = placemarks.location?.cordinate.latitude
let eventLongitude = placemarks.location?.coordinate.longitude
let eventLocation = CLLocation(latitude: eventLatitude!, longitude: eventLongitude!)

我相信您需要访问 placemarks.first.locationplacemarks[0].location

关于快速向前地理定位并访问地标经度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33681739/

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