简体   繁体   English

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

[英]Swift GeoPoint get ALL users location ios

I am trying to make a app where everyone can see everyones location at the same map. 我正在尝试制作一个每个人都可以在同一张地图上看到每个人的位置的应用程序。 I can't find any tutorials on how to retrieve ALL users location on the same map. 我找不到有关如何在同一张地图上检索所有用户位置的任何教程。

I have manage to make a script which uploads the users location into Parse with this script: 我设法制作了一个脚本,该脚本使用以下脚本将用户位置上传到Parse中:

PFGeoPoint.geoPointForCurrentLocationInBackground {


            (geoPoint: PFGeoPoint?, Error : NSError?) -> Void in
   if let geoPoint = geoPoint{

        PFUser.currentUser()? ["location"] = geoPoint
    PFUser.currentUser()?.saveInBackground()

I have also manage to get the location of the current user. 我还设法获取了当前用户的位置。

Any one know how i can display everyones location, not just mine? 有谁知道我可以显示每个人的位置,而不仅仅是我的位置?

Thank you for your time and help. 感谢您的时间和帮助。 I am very new to Swift so let me know if i need to provide more information. 我对Swift非常陌生,所以请告诉我是否需要提供更多信息。

Here is my display code. 这是我的显示代码。

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

Outside ViewWDidLoad 外部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()



    }

To get all users location is not so simple as you think. 要获得所有用户的位置并不是您想的那么简单。 The most time regular app is working in the background. 最常使用的常规应用在后台运行。 In the background app can be in background or suspended or terminated state ( about states ). 在后台应用程序可以处于后台或暂停或终止状态( 关于状态 )。 And you have to get location from any of these states. 而且您必须从任何这些州获得位置。
How is it possible: you should enable Background Mode for location tracking for your app. 怎么可能:您应该启用后台模式来跟踪您的应用。 To do it simpler - use significant location tracking for all users, but accuracy will be about 500m. 若要简化操作-对所有用户使用重要的位置跟踪,但准确性约为500m。
To get more accuracy (but more difficult implementation) you can send silent push notification to users ( about silent push ), it wakes up app from terminated or suspended states to background state, and now you can get and send users current location to your server. 要获得更高的准确性(但实施起来会困难),您可以向用户发送静默推送通知( 关于静默推送 ),它将应用程序从终止或挂起状态唤醒到后台状态,现在您可以获取并发送用户当前位置到您的服务器。

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

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