I'd like to know about PFGeoPoint
class. I read about it on Parse site but i got a question that doesn't seem to have answer.
I need to save PFGeoPoint
and to make it visibile to all user that use my application and i really don't know why. Can PFGeoPoint
do it??
My app is quite simply: you can login (PFUser
) and place a mark on a map where's a little fountain (for people who're looking for it). And i want to make all fountains marked (by all users) visibile to all other users unless i deleted it from parse.
@IBAction func changed(sender: UISegmentedControl) {
switch rateFountain.selectedSegmentIndex
{
case 0:
voto.text = "Good";
break;
case 1:
voto.text = "Bad";
break;
default:
voto.text = "Good";
break;
}
}
@IBAction func logout(sender: UIButton) {
PFUser.logOut()
print("Log Out Done")
self.performSegueWithIdentifier("gotoLogin", sender: self)
}
@IBOutlet weak var map: MKMapView!
@IBAction func addFountain(sender: UIButton) {
let ObFountain = PFObject(className: "Fountain")
ObFountain["nome"] = nome.text
ObFountain["voto"] = voto.text
let fountain = MKPointAnnotation()
fountain.coordinate = posizioneUtente
fountain.title = nome.text
fountain.subtitle = voto.text
self.map.addAnnotation(fountain)
}
var MapViewLocationManager:CLLocationManager! = CLLocationManager()
var managerPosizione: CLLocationManager! //gestisce oggetti LocationManager
var posizioneUtente: CLLocationCoordinate2D!//coordinate
override func viewDidLoad() {
super.viewDidLoad()
managerPosizione = CLLocationManager() //inizializzo il locationManager che recupera la posizione utente
managerPosizione.delegate = self
managerPosizione.desiredAccuracy = kCLLocationAccuracyNearestTenMeters //setto l'accuratezza della nostra posizione con un errore di non oltre dieci metri
managerPosizione.requestAlwaysAuthorization() // richiede da parte dell'utente utilizzatore l'attivazione delle funzioni di geolocalizzazione
managerPosizione.startUpdatingLocation() // tiene traccia del cambiamento di posizione
// Do any additional setup after loading the view.
}
func viewDidApperar(animated : Bool){
}
//avvisa il delegate che le coordinate dell'utente sono state aggiornate
func mapView(mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation) {
posizioneUtente = userLocation.coordinate //salvo le coordinate dell'utente nella variabile
print("posizione aggiornata - lat: \(userLocation.coordinate.latitude) long: \(userLocation.coordinate.longitude)")
let span = MKCoordinateSpanMake(0.05, 0.05) // estensione dell'area da visualizzare
let region = MKCoordinateRegion(center: posizioneUtente, span: span) // calcola le coordinate della regione
mapView.setRegion(region, animated: true) //aggiorna la mapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
//se l'annotation è la posizione dell'Utente allora esci dalla funzione e mostra il punto blu
if annotation is MKUserLocation {
return nil
}
//creo un id da associare ad ogni annotationView
let reuseId = "punto"
//se esistono troppi punti nella mappa, prende quello non visto e lo riutilizza nella porzione di mappa vista
var puntoView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
//se non è stata ancora creata un'AnnotationView la crea
if puntoView == nil {
//creo un pin di tipo MKAnnotationView che rappresenta l'oggetto reale da inserire in mappa
puntoView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
//cambio l'immagine standard del point annotation con una creata da me
puntoView!.image = UIImage(named: "nella30.png")
//sblocco la possibilità di cliccarlo per vedere i dettagli
puntoView!.canShowCallout = true
}
else {
//se esiste lo modifico con il nuovo point richiesto
puntoView!.annotation = annotation
}
//restituisce un pointAnnotation nuovo o modificato
return puntoView
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?){
view.endEditing(true)
super.touchesBegan(touches, withEvent: event)
}
My wish is to set the fountain when i press the button with my current Location and rated it with good or bad. And to show this to all users who use app. I'm pretty newbie to swift so you might be helping me with code directly. I'd appreciate a lot that