2016-12-04 73 views
0

有沒有什麼方法可以實時跟蹤Facebook用戶的位置,他們已登錄我的移動應用程序,並且已啓用位置服務,並且已授予訪問我的應用程序的權限利用它的位置?如何跟蹤facebook當前用戶的位置IOS/Android

  1. 假設用戶X和空間中有3個線性點:A,B,C。 X從A到C旅行

  2. 是否有一個SDK可以讓我在X從A移動到C的任何給定時間檢查X的實時位置(緯度+經度),從而創建一個在每10ms用戶位置點綴地圖(通過在地圖上放置一個別針)?

  3. 鑑於我的設備具有4G互聯網連接,這是否可行?

回答

1

我想你可以使用CLLocationManager來更新用戶位置後旅行了幾米。我認爲你已經有一個CLLocationManager來更新你的位置?您可以將點保存在數組中(從A的位置開始,以C的位置結束)。然後你可以用點畫一條線。我相信Google Map API有一個繪製線條的方法。還有的是,這裏的答案:

Here is a link from SO

但對於提供代碼的緣故,我在雨燕3.0提供爲您(在鏈接的代碼是在ObjC):

override func viewDidLoad() { 
    super.viewDidLoad() 
    //This is a dummy location, you'd add locations to it using the 
    // func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 
    let location:CLLocation = CLLocation(latitude: 200, longitude: 100) 
    let locationArray:Array<CLLocation> = [location] 
    let camera:GMSCameraPosition = GMSCameraPosition.camera(withLatitude: (locationArray.first?.coordinate.latitude)!, longitude: (locationArray.first?.coordinate.longitude)!, zoom: 2) 
    //You can obtain the Lat and Long for above from the list of arrays of locations you saved 
    //You can use the .first or .last on the array (I used first) 

    let mapview:GMSMapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 

    let path:GMSMutablePath = GMSMutablePath() 
    for nextLocation in locationArray { 
     if locationArray.index(of: nextLocation) != 0 { 
      //You dont want to use the first one as you've already done it 
      //so you start with 1 
      path.addLatitude(nextLocation.coordinate.latitude, longitude: nextLocation.coordinate.longitude) 
     } 
    } 

    let polyline:GMSPolyline = GMSPolyline(path: path) 
    polyline.strokeColor = UIColor.red 
    polyline.strokeWidth = 2 
    polyline.map = mapview 
    self.view = mapview 

    //I personally prefer view.addSubview(mapview) 
}