Vote count:
0
I have the following method that saves points to Parse.com
using the PFGeoPoint
object:
func addPolygonToMap() {
var numberOfPoints: NSInteger = self.coordinates.count
if (numberOfPoints > 4) {
var points: [CLLocationCoordinate2D] = []
for i in 0..<numberOfPoints {
points.insert(self.coordinates[i].MKCoordinateValue, atIndex: i)
}
// Save to Parse object.
var geofenceUserObject = PFObject(className: "GeofenceUser")
let geofenceId = self.generateUUID()
geofenceUserObject["UserId"] = "IjlpQHwyfG"
geofenceUserObject["GeofenceId"] = geofenceId
geofenceUserObject.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError!) in
if (error != nil) {
println("Error saving: \(error)")
} else if (succeeded) {
var index: NSInteger = 0
for point in points {
var geoPoint = PFGeoPoint(latitude: point.latitude, longitude: point.longitude)
var geofenceObject = PFObject(className: "GeofenceCoordinates")
geofenceObject["Point"] = geoPoint
geofenceObject["GeofenceId"] = geofenceId
geofenceObject.saveInBackgroundWithBlock({ (operation, error) in
index = index + 1
if (index == points.count) {
self.polygon = MKPolygon(coordinates: &points, count: numberOfPoints)
self.mapView.addOverlay(self.polygon)
}
})
}
}
})
}
}
This is an example MKpolygon
that gets created:
This is the method I'm using to add the points to the map:
var query = PFQuery(className: "GeofenceCoordinates")
query.orderByAscending("createdAt")
query.whereKey("GeofenceId", equalTo: geofenceId)
query.findObjectsInBackgroundWithBlock({ (objects, error) in
if let objects = objects as? [PFObject] {
var coordinates: Array<CLLocationCoordinate2D> = []
for point in objects {
if let coordinate = point.objectForKey("Point") as? PFGeoPoint {
let c = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
coordinates.append(c)
}
}
let polygon = MKPolygon(coordinates: &coordinates, count: coordinates.count)
self.mapView.addOverlay(polygon)
}
})
The problem is that when I retrieve these points from Parse I get the following MKPolygon
instead, which is missing quite a few points and looks incomplete.
I'm not quite sure whether it's my way of persisting the data or the way I'm retrieving the data.
asked 39 secs ago
Issue persisting MKPolygon points using Parse framework
Aucun commentaire:
Enregistrer un commentaire