2016-12-04 9 views
0

Facebookのユーザーの場所をリアルタイムでトラッキングできる方法はありますか?モバイルアプリにログインし、位置情報サービスを有効にしています。その場所を利用する?facebookの現在のユーザーの場所を追跡する方法

  1. ユーザXとスペース内の3つの線形ポイント:A、B、Cを仮定します。 XはAからCへ移動しています。

  2. XがAからCに移動している間に、Xのリアルタイム位置(緯度+経度)をいつでも確認できるSDKはありますか? 10msごとにユーザーの位置を点線で示したマップ(地図上にピンをドロップすることによって)?

  3. 私のデバイスが4Gインターネット接続を使用していることを考えれば実現可能ですか?

答えて

1

CLLocationManagerを使用して、いくつかのメーターを移動した後にユーザーの場所を更新できると思います。私はあなたの場所を更新するために既にCLLocationManagerを持っていると思いますか?配列の中にドットを保存することができます(Aの位置から始まり、Cの位置で終わる)。その後、点を使用して線を描くことができます。 Google Map APIには線を描画するメソッドがあると思います。 (リンクのコードがにObjCである)

Here is a link from SO

しかし、コードを提供するために、私はスウィフト3.0にあなたのためにそれを提供します:そこここにそのための答えです

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) 
} 
関連する問題