ios - 添加带有点击手势的图钉时,我的图钉会显示在其他地方。
问题描述
如您所见,一切正常,但由于某种原因,当我将图钉添加到地图时,纬度和经度显示在不同的部分。
不知道还能做什么,所以这是我最后的手段..
这只是片段
在这里,我正在启动手势识别器
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(gesturer:)))
mapview?.addGestureRecognizer(longGesture)
添加注释
func addAnnotationOnLocation(pointedCoordinate: CLLocationCoordinate2D) {
let annotation2 = MKPointAnnotation()
annotation2.coordinate = pointedCoordinate
annotation2.title = text.text
mapview?.addAnnotation(annotation2)
print("\(text.text)annotation")
}
以及在数据库和地图上完成的工作以添加注释
@objc func handleLongPress (gesturer: UILongPressGestureRecognizer) {
if gesturer.state == UIGestureRecognizer.State.began {
print("began")
let alertController = UIAlertController(title: "Enter Activity", message: "Enter Below", preferredStyle: UIAlertController.Style.alert)
alertController.addTextField { (textfield: UITextField) in
textfield.placeholder = "activity here"
}
alertController.addAction(UIAlertAction(title: "Add", style: UIAlertAction.Style.default, handler: { (action: UIAlertAction) in
if let alertTextfield = alertController.textFields?.first, alertTextfield.text != nil {
// print("text here\(String(describing: alertTextfield.text))")
// self.text = alertTextfield
DispatchQueue.main.async {
print("text here\(String(describing: alertTextfield.text))")
self.text = alertTextfield
let touchPoint : CGPoint = gesturer.location(in: self.mapview)
let newCoordinate: CLLocationCoordinate2D = (self.mapview?.convert(touchPoint, toCoordinateFrom: self.mapview))!
self.myPoints.append(newCoordinate)
print(newCoordinate.latitude, newCoordinate.longitude)
self.userpinning = newCoordinate
self.addAnnotationOnLocation(pointedCoordinate: newCoordinate)
guard let uid = Auth.auth().currentUser?.uid else {return}
let ref = Database.database().reference().child("Map1").child(uid)
let values = ["lat": self.userpinning.latitude, "long": self.userpinning.latitude, "Captio": self.text.text, "CreatingDate": Date().timeIntervalSince1970] as [String: Any]
let mapref = ref.childByAutoId()
mapref.updateChildValues(values, withCompletionBlock: { (err, ref) in
print("err", err)
})
}
}
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: { (_) in
alertController.dismiss(animated: true, completion: nil)
}))
self.present(alertController, animated: true, completion: nil)
}
}
解决方案
推荐阅读
- signals - Kibana/Vega 中的地图和信号纬度、经度和缩放
- multithreading - Docker 与线程同时创建网络
- javascript - puppeteer 点击打开新标签并抓取所有图像
- r - 上面带有不变行的进度条(在 R 中)
- c - 在 Xcode Objective-C 项目中为 C 文件指定 Makefile
- static-analysis - 在“if”子句中对 ACSL 的函数调用
- asp.net-mvc - 使用 TextBoxfor 时,数据未从局部视图绑定到模型
- javascript - 在鼠标滚轮事件上检测左右
- ios - 如何在 iOS 中使用 Live Stream URL 更改 AVPlayer 中的视频质量?
- reactjs - 使用数组从对象的反应状态更新选定的属性