我正在尝试使用CLGeocoder().reverseGeocodeLocation.
它给了我国家名称、街道名称、州和许多其他东西,但没有城市。我的代码有什么问题吗?
这是我的代码:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
CLGeocoder().reverseGeocodeLocation(location) { (placeMark, error) in
if error != nil{
print("Some errors: \(String(describing: error?.localizedDescription))")
}else{
if let place = placeMark?[0]{
print("country: \(place.administrativeArea)")
self.lblCurrentLocation.text = place.administrativeArea
}
}
} }
Run Code Online (Sandbox Code Playgroud)
我也使用下面的代码。但对我不起作用。这是另一种方式。
let geoCoder = CLGeocoder()
let location = CLLocation(latitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location?.coordinate.longitude)!)
geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
// Place details
var placeMark: CLPlacemark!
placeMark = placemarks?[0]
// Address dictionary
print(placeMark.addressDictionary …Run Code Online (Sandbox Code Playgroud) 我在核心数据实体中有几项作业,其 jobId 为 -1。我需要获取所有这些项目并通过在我的对象中通过 updateMyJobs 方法传递的正确 id 更新 jobId。我还没有提取 NSManagedObject 类来处理核心数据(即 - 我已经将实体检查为类定义)
这是我的代码:
func updateMyJobs(jobId: Int){
managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "DBJobsNearBy")
fetchRequest.predicate = NSPredicate(format: "jobId = '-1'")
let result = try? managedObjectContext.fetch(fetchRequest)
let resultData = result as! [DBJobsNearBy]
for object in resultData {
print(object.jobId)
if object.jobId == -1 {
object.setValue("\(jobId)", forKey: "jobId")
}
}
do {
try managedObjectContext.save()
print("saved!")
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}
Run Code Online (Sandbox Code Playgroud)
我传递了一些整数值并调用上面的方法来更新这样的项目。 …
我正在尝试实现 facebook 登录。从https://www.youtube.com/watch?v=MNfrBdyEvmY学习,但有上述类型的错误。这是我的代码:
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start { (connection, result, error) in
if error != nil{
print(error ?? "error")
return
}
if let email = result["email"] as? String{
print("Email: \(email)")
}
}
Run Code Online (Sandbox Code Playgroud)