只有一个大头针出现在Map上- Swift

vybvopom  于 2023-02-15  发布在  Swift
关注(0)|答案(1)|浏览(102)

用户在Map上固定了多个大头针。我只想显示最后一个大头针,你能帮我吗?
@objc函数选择Pin(Map手势:UI长按手势识别器){

if mapGesture.state == .began {
        
        let touchPoint = mapGesture.location(in: self.mapview)
        let touchCoordinates = self.mapview.convert(touchPoint, toCoordinateFrom: self.mapview)
        choosenLatitude = touchCoordinates.latitude
        choosenLongtitude = touchCoordinates.longitude
        
        let annotation = MKPointAnnotation()
        annotation.coordinate = touchCoordinates
        annotation.title = forWhatText.text
        if forWhatText.text == "" {
            makeAlert(titleInput: "Error", messageInput: "Please fill in all the fields above!")
        } else if phoneName.text == "" {
            makeAlert(titleInput: "Error", messageInput: "Please fill in all the fields above!")
        } else if phoneNumber.text == "" {
            makeAlert(titleInput: "Error", messageInput: "Please fill in all the fields above!")
        } else if messageText.text == "" {
            makeAlert(titleInput: "Error", messageInput: "Please fill in all the fields above!")
        } else {
            mapview.addAnnotation(annotation)
            //saveButton.isEnabled = true
        }
    }
}
a64a0gku

a64a0gku1#

使用mapGesture.state == . ended代替mapGesture.state == . begin中的添加引脚

相关问题