0
我正在嘗試製作一個應用程序,每個人都可以在同一個地圖上看到每個人的位置。我找不到關於如何在同一張地圖上檢索所有用戶位置的教程。Swift GeoPoint獲取所有用戶的位置ios
我必須設法使一個腳本,這個腳本上傳用戶的位置成解析:
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, Error : NSError?) -> Void in
if let geoPoint = geoPoint{
PFUser.currentUser()? ["location"] = geoPoint
PFUser.currentUser()?.saveInBackground()
我也設法獲取當前用戶的位置。
任何人都知道我如何顯示每個人的位置,不只是我的?
謝謝你的時間和幫助。我對Swift很陌生,所以讓我知道我是否需要提供更多信息。
這是我的顯示代碼。
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, Error : NSError?) -> Void in
if let geoPoint = geoPoint{
PFUser.currentUser()? ["location"] = geoPoint
PFUser.currentUser()?.saveInBackground()
self.MapView?.showsUserLocation = true
self.MapView?.delegate = self
MapViewLocationManager.delegate = self
MapViewLocationManager.startUpdatingLocation()
self.MapView?.setUserTrackingMode(MKUserTrackingMode.Follow, animated: false)
self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled(){
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocationManager]){
var locValue:CLLocationCoordinate2D = (manager.location?.coordinate)!
print("locations = \(locValue.latitude) \(locValue.longitude)")
外ViewWDidLoad
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.MapView?.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
誰是「大家」?你的應用的其他用戶? – Moritz
是的。其他成員。 –
那麼這不就是如何從Parse API獲取所有用戶的問題嗎?這不是在他們的文檔中的某處嗎?我試圖瞭解你的問題的實際性質。目前這個問題似乎對於SO非常廣泛和模糊。 :) – Moritz