При добавлении булавки жестом касания моя булавка появляется где-то еще..

Как видите, все работает отлично, но по какой-то причине, когда я добавляю булавку на карту, широта и долгота отображаются в другой части.

Не уверен, что еще делать, так что это мое последнее средство..

это всего лишь фрагмент

здесь я инициирую распознаватель жестов

    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)

    }
}

0 ответов

Другие вопросы по тегам