2016-01-13 18 views
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() 



    } 
+0

谁是“大家”?你的应用的其他用户? – Moritz

+0

是的。其他成员。 –

+0

那么这不就是如何从Parse API获取所有用户的问题吗?这不是在他们的文档中的某处吗?我试图了解你的问题的实际性质。目前这个问题似乎对于SO非常广泛和模糊。 :) – Moritz

回答

0

要得到所有用户的位置并不像你想象的那么简单。最常见的应用程序正在后台工作。在后台应用程序可以在后台或暂停或终止状态(about states)。你必须从这些州的任何一个获得位置。
这怎么可能:您应该为您的应用程序启用背景模式以进行位置跟踪。要做到这一点更简单 - 为所有用户使用重要的位置跟踪,但准确度将达到500米左右。
为了得到更准确(但很难实现),您可以发送无声推送通知用户(about silent push),它终止或暂停状态唤醒应用到后台状态,现在你可以发送用户的当前位置到您的服务器。