2016-12-04 68 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) 
}