0

I'm trying to do exactly this using Parse and Swift.

import UIKit
import MapKit
import CoreLocation

class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

var latitude:Double = 0.0
var longitude:Double = 0.0

@IBOutlet var map: MKMapView!


override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.setNavigationBarHidden(true , animated: true)
    self.map.showsUserLocation = true
    self.map.delegate = self


    PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint:PFGeoPoint?, error:NSError?) -> Void in

        var query = PFQuery(className: "Locations")
        query.whereKey("geopoint", nearGeoPoint: geopoint!)
        query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

            if let myObjects = objects {

                for object in myObjects {

                    var thePoint: PFGeoPoint = object["geopoint"] as! PFGeoPoint
                    self.latitude = thePoint.latitude
                    self.longitude = thePoint.longitude
                    NSLog(" Hej %f, %f", self.latitude, self.longitude)
                    var annotationCoordinate: CLLocationCoordinate2D = CLLocationCoordinate2DMake(self.latitude, self.longitude)
                    var annotation = MKPointAnnotation()
                    annotation.coordinate = annotationCoordinate
                    annotation.title = object["discovery"] as! String
                    annotation.subtitle = object["location"] as! String
                    self.map.addAnnotation(annotation)

                }
            }
        }
    }
}

Big picture though, I'm trying to create a way to access pictures stored on Parse (and their locations) and display them on a map if they meet my query. I greatly appreciate any help!

Community
  • 1
  • 1

1 Answers1

0

if you are getting the conversion error in

var thePoint: PFGeoPoint = object["geopoint"]

change it to

var thePoint: PFGeoPoint = object["geopoint"] as! PFGeoPoint

Regarding converting Double to Int, it appears to be as you found but I don't know the rationale behind the decision by the designers of swift. I would like to understand why you need the conversion since there may be an alternate implementation

Syed Tariq
  • 2,878
  • 3
  • 27
  • 37
  • I've updated my original code based on your comment. I'm now able to build without any errors! I'm still working on getting to the point where I have a map with photos. Thank you for your help. – Emile Frey May 22 '15 at 02:43