繁体   English   中英

Swift GeoPoint获取所有用户的位置ios

[英]Swift GeoPoint get ALL users location ios

我正在尝试制作一个每个人都可以在同一张地图上看到每个人的位置的应用程序。 我找不到有关如何在同一张地图上检索所有用户位置的任何教程。

我设法制作了一个脚本,该脚本使用以下脚本将用户位置上传到Parse中:

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()



    }

要获得所有用户的位置并不是您想的那么简单。 最常使用的常规应用在后台运行。 在后台应用程序可以处于后台或暂停或终止状态( 关于状态 )。 而且您必须从任何这些州获得位置。
怎么可能:您应该启用后台模式来跟踪您的应用。 若要简化操作-对所有用户使用重要的位置跟踪,但准确性约为500m。
要获得更高的准确性(但实施起来会困难),您可以向用户发送静默推送通知( 关于静默推送 ),它将应用程序从终止或挂起状态唤醒到后台状态,现在您可以获取并发送用户当前位置到您的服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM