【发布时间】:2015-11-23 17:04:19
【问题描述】:
我想了解PFGeoPoint 课程。我在 Parse 网站上读到了它,但我得到了一个似乎没有答案的问题。
我需要保存PFGeoPoint 并使其对所有使用我的应用程序的用户可见,我真的不知道为什么。 PFGeoPoint可以吗??
我的应用程序非常简单:您可以登录 (PFUser) 并在地图上标记一个小喷泉(对于正在寻找它的人)。而且我想让所有其他用户(由所有用户)标记的所有喷泉都对所有其他用户可见,除非我从解析中删除它。
@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)
}
我的愿望是在我按下带有当前位置的按钮时设置喷泉,并对其进行评价为好或坏。并将其展示给所有使用 app 的用户。我是 swift 的新手,所以您可能会直接帮助我编写代码。我会很感激的
【问题讨论】:
标签: ios xcode swift parse-platform