我有一个地图和两个按钮。地图自动定位用户,如果他或她按下按钮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