簡體   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