我有一個地圖和兩個按鈕。地圖自動定位用戶,如果他或她按下按鈕1,它會保存當前位置以進行解析。這工作正常。但是,如果您在地圖上的其他地方導航並放置一個別針,我希望在您點擊按鈕2時將該地點推送到解析,但它只是推動當前位置。丟棄引腳不推送位置數據使用Swift分析
我想我離我很近,我只是需要一點點幫助才能工作。
這裏是我的代碼
self.locationManager.delegate = self
self.mapView.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
let longPress = UILongPressGestureRecognizer(target: self, action: "mapLongPress:")
longPress.minimumPressDuration = 1.5
self.mapView.addGestureRecognizer(longPress)
var mapChangedFromUserInteraction = false
func mapViewRegionDidChangeFromUserInteraction() -> Bool {
let view = self.mapView.subviews[0]
// Look through gesture recognizers to determine whether this region change is from user interaction
if let gestureRecognizers = view.gestureRecognizers {
for recognizer in gestureRecognizers {
if(recognizer.state == UIGestureRecognizerState.Began || recognizer.state == UIGestureRecognizerState.Ended) {
return true
}
}
}
return false
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func mapLongPress(recognizer: UIGestureRecognizer){
print("its done")
let touchedAt = recognizer.locationInView(self.mapView)
let touchedAtCoordinate : CLLocationCoordinate2D = mapView.convertPoint(touchedAt, toCoordinateFromView: self.mapView)
let newPin = MKPointAnnotation()
newPin.coordinate = touchedAtCoordinate
mapView.removeAnnotations(mapView.annotations)
mapView.showsUserLocation = false
mapView.addAnnotation(newPin)
}
@IBAction func photographer(sender: AnyObject, forEvent event: UIEvent) {
let manager = CLLocationManager()
let loc = manager.location!.coordinate
let actualLocation = PFGeoPoint(latitude:loc.latitude,longitude:loc.longitude)
let object = PFObject(className:"User")
object["Location"] = actualLocation
object.saveInBackgroundWithBlock { (_success:Bool, _error:NSError?) -> Void in
if _error == nil
{
// yay its saved
}
}
}
@IBAction func buyer(sender: AnyObject, forEvent event: UIEvent) {
}
你可能只是包含處理你的代碼問題,我對所做的一切有點困惑。 –
這是處理地圖的所有代碼,我把所有其他的東西都拿出來了 – RubberDucky4444
@IBAction func買家...是按鈕#2,我不知道在那裏放什麼 – RubberDucky4444