我试图创建一个具有两种用户类型的应用程序...一个发送一个位置,另一个用户类型(在另一个设备上)搜索一个区域并找到最近的用户。

&# xA;我一直在解析网站和堆栈溢出......他们似乎都从中间开始。我希望有人解释第一步


继承我的代码


 导入UIKit&#xA ;导入MapKit
导入CoreLocation
导入Parse

类ViewController:UIViewController,MKMapViewDelegate,
 CLLocationManagerDelegate,UISearchBarDelegate,
 UIGestureRecognizerDelegate
 {
&# xA; @IBOutlet weak var photographer1:UIButton!
 @IBOutlet weak var buyer1:UIButton!

 @IBOutlet weak var mapView:MKMapView!
 @IBOutlet weak var searchBar:UISearchBar! 

让locationManager = CLLocationManager()

 var searchController:UISearchController!
 var annotation:MKAnnotation!
 var localSearchRequest:MKLocalSearchRequest!
 var localSearch:MKLocalSearch!
 var localSearchResponse:MKLocalSearchResponse!
 var error:NSError!
 var pointAnnotation:MKPointAnnotation!
 var pinAnnotationView:MKPinAnnotationView!

 override func viewDidLoad中()
 {
 super.viewDidLoad()

 self.locationManager.delegate = self
 self.mapView.delegate = self
 self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
 self.locationManager.requestWhenInUseAuthorization()
 self.locationManager.startUpdatingLocation()
 self.mapView.showsUserLocation = true

}
 //运行动画这段代码检查区域是否已更改


 var mapChangedFromUserInteraction = false

 func mapViewRegionDidChangeFromUserInteraction() - > Bool {
让view = self.mapView.subviews [0]
 //查看手势识别器以确定此区域更改是否来自用户交互
如果让gestureRecognizers = view.gestureRecognizers {
 for gestureRecognizers中的识别器{
 if(recognizer.state == UIGestureRecognizerState.Began || Recognizer.state == UIGestureRecognizerState.Ended){
返回true
 }
 }
 }
 return false
}

 func mapView(mapView:MKMapView,regionWillChangeAnimated animated:Bool){
 mapChangedFromUserInteraction = mapViewRegionDidChangeFromUserInteraction()
 if(mapChangedFromUserInteraction){
 //用户更改了地图区域
 }
}

 func mapView(mapView:MKMapView,regionDidChangeAnimated animated:Bool){
 if(mapChangedFromUserInteraction){
 hobo()

 //
 buyer1.center = CGPointMake(188.0,513.0)

 photographer1.center = CGPointMake(188.0,581.0)

 }
}

 //你的男孩

 // MARK: - 位置代理方法

 func locationManager(经理:CLLocationManager,didUpdateLocations位置: [CLLocation])
 {
 let location = locations.last

 let center = CLLocationCoordinate2D(纬度:location!.coordinate.latitude,经度: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 locationManager(manager:CLLocationManager,didFailWithError error:NSError)
 {
 print(“错误:”+ error.localizedDescription)

}


 func searchBarSearchButtonClicked(searchBar:UISearchBar){
 // 1
 searchBar.resignFirstResponder()
 dismissViewControllerAnimated(true,completion:nil)
 if self.mapView.annotations.count!= 0 {
 annotation = self.mapView.annotations [0]
 self.mapView.removeAnnotation(注释)
 }
 // 2
 localSearchRequest = MKLocalSearchRequest()
 localSearchRequest.naturalLanguageQuery = searchBar.text
 localSearch = MKLocalSearch(请求:localSearchRequest)
 localSearch.startWithCompletionHandler {(localSearchResponse,error) - >无效

如果localSearchResponse == nil {
 let alertController = UIAlertController(title:nil,message:“Place Not Found”,preferredStyle:UIAlertControllerStyle.Alert)
 alertController.addAction(UIAlertAction(标题:“Dismiss”,样式:UIAlertActionStyle.Default,handler:nil))
 self.presentViewController(alertController,animated:true,completion:nil)
返回
 }
 // 3
 self.pointAnnotation = MKPointAnnotation()
 self.pointAnnotation.title = searchBar.text
 self.pointAnnotation.coordinate = CLLocationCoordinate2D(纬度:localSearchResponse!.boundingRegion.center.latitude,经度:localSearchResponse!.boundingRegion.center.longitude)


 self.pinAnnotationView = MKPinAnnotationView(注释:self.pointAnnotation,reuseIdentifier:nil)
 self.mapView.centerCoordinate = self.pointAnnotation.coordinate
 self.mapView.addAnnotation&#XA(self.pinAnnotationView.annotation!);
 }
}

 func hobo(){
 print(“testing”)
}

 @IBAction func showSearchBar(sender:AnyObject){
 searchController = UISearchController(searchResultsController:nil)
 searchController.hidesNavigationBarDuringPresentation = false
 self.searchController.searchBar.delegate = self
 presentViewController(searchController,animated:true,completion:nil)

}


 @IBAction func locateMe(sender:AnyObject){
 self.mapView.showsUserLocation = true
 self.locationManager.startUpdatingLocation()
 self.locationManager.delegate = self
 self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
 self.locationManager.requestWhenInUseAuthorization()


 buyer1.center = CGPointMake(188.0,581.0)

 photographer1.center = CGPointMake(188.0,513.0)

}

 @IBAction func photographer(sender:AnyObject){
}

 @IBAction func买家(发件人:AnyObject){
}

}