2017-07-04 3 views
-1

Parseサーバーの保存済みPFGeopointオブジェクトを注釈に変換しようとしていますが、わかりませんが何が問題なのかわかりません。 私はこの質問のコードを適用しようとしました:Converting Parse GeoPoint into a CLLocation in Swiftしかし、私はまだそれを把握できませんでした。Parse PFGeoPointをマップ上の注釈に変換する

は、ここに私のコードです:

import UIKit 
import MapKit 
import CoreLocation 
import Parse 

class MapVC: UIViewController, MKMapViewDelegate { 


fileprivate let locationManager = CLLocationManager() 
fileprivate var startedLoadingPOIs = false 
fileprivate var places = [Place]() 


var descLocation: PFGeoPoint = PFGeoPoint() 
var mapHasCenteredOnce = false 

    @IBOutlet weak var mapView: MKMapView! 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     mapView.delegate = self 

     locationManager.delegate = self 
     locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters 
     locationManager.startUpdatingLocation() 
     locationManager.requestWhenInUseAuthorization() 
     mapView.userTrackingMode = MKUserTrackingMode.followWithHeading 

    } 

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

     var annotationView: MKAnnotationView? 

     if annotation.isKind(of: MKUserLocation.self) { 
      annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "User") 
      annotationView?.image = UIImage(named: "loc.png") 
     } 

     return annotationView 
    } 






} 




extension MapVC: CLLocationManagerDelegate { 




    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 



     //1 
     if locations.count > 0 { 
      let location = locations.last! 
      print("Accuracy: \(location.horizontalAccuracy)") 

      //2 
      if location.horizontalAccuracy < 100 { 
       //3 
       manager.stopUpdatingLocation() 
       let span = MKCoordinateSpan(latitudeDelta: 0.014, longitudeDelta: 0.014) 
       let region = MKCoordinateRegion(center: location.coordinate, span: span) 
       mapView.region = region 

       if !startedLoadingPOIs { 
        startedLoadingPOIs = true 
        let loader = PlacesLoader() 
        loader.loadPOIS(location: location, radius: 1000) { placesDict, error in 
         if let dict = placesDict { 


          let query = PFQuery(className: "posts") 
          if let latitude = (PFUser.current()?["location"] as AnyObject).latitude { 
           if let longitude = (PFUser.current()?["location"] as AnyObject).longitude { 
            let geoPoint = PFGeoPoint(latitude: latitude, longitude: longitude) 
            query.whereKey("postLocation", nearGeoPoint: geoPoint, withinKilometers: 1) 
           } 
          } 
          query.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in 
           if error == nil { 



            for object in objects! { 
             let pfObject = object as PFObject 

             let caption = pfObject["title"] as! String 

             self.descLocation = object["postLocation"] as! PFGeoPoint 

             let latitude: CLLocationDegrees = self.descLocation.latitude 
             let longitude: CLLocationDegrees = self.descLocation.longitude 
             let location = CLLocation(latitude: latitude, longitude: longitude) 

             let place = Place(location: location, name: caption) 
             self.places.append(place) 
             let annotation = PlaceAnnotation(location: place.location!.coordinate, title: place.placeName) 
             DispatchQueue.main.async { 
             self.mapView.addAnnotation(annotation) 
             } 

            } 
           } 
          } 



         } 
        } 
       } 


} 
} 
} 


} 
+0

へようこそSO!次の内容を確認し、受け取ったエラーを追加して誰かの回答に役立ててください: https://stackoverflow.com/help/how-to-ask – garfbradaz

答えて

0

私は、操作をブロックし、それらを取り外した2つのuanessacryラインを持っていたし、それは私のために働きました。

loader.loadPOIS(場所、場所、半径:1000){placesDict、辞書= placesDictを許可すれば におけるエラー{

関連する問題