用户在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
}
}
}
1条答案
按热度按时间a64a0gku1#
使用mapGesture.state == . ended代替mapGesture.state == . begin中的添加引脚