2017-10-17 3 views
0

Firebaseから引っ張られた地図表示の場所を私のユーザーから半マイル圏内にしようとしていますが、私はまだそこにいません。誰でも助けてくれますか?Firebaseでの会場の表示ユーザーが近くにいるとき

これは私が今やっていることです:

1)私のviewDidLoadの私FirebaseデータベースからのデータとマップとのtableViewを読み込む:

var posts = [Post]() 
 

 
    override func viewDidLoad() { 
 
     super.viewDidLoad() 
 

 
     // Set up Map 
 
     mapView.delegate = self 
 
     mapView.userTrackingMode = MKUserTrackingMode.follow 
 

 
     // Setup TableView 
 
     tableView.delegate = self 
 
     tableView.dataSource = self 
 

 
     //Pulls TableData for UITableView 
 
     DataService.ds.REF_VENUE.observe(.value, with: { (snapshot) in 
 

 
      self.posts = [] // THIS IS THE NEW LINE 
 
      if let snapshot = snapshot.children.allObjects as? [DataSnapshot] { 
 
       for snap in snapshot { 
 
        if let postDict = snap.value as? Dictionary<String, AnyObject> { 
 
         let key = snap.key 
 
         let post = Post(postKey: key, postData: postDict) 
 
         self.posts.append(post) 
 
        } 
 

 
        //Populates Map with annotations. 
 
        if let locationDict = snap.value as? Dictionary<String, AnyObject> { 
 

 
         let lat = locationDict["LATITUDE"] as! CLLocationDegrees 
 
         let long = locationDict["LONGITUDE"] as! CLLocationDegrees 
 
         let title = locationDict["NAME"] as! String 
 
         let center = CLLocationCoordinate2D(latitude: lat, longitude: long) 
 
         _ = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.20, longitudeDelta: 0.20)) 
 

 
         let annotation = MKPointAnnotation() 
 
         annotation.coordinate = CLLocationCoordinate2DMake(lat, long) 
 
         annotation.title = title.capitalized 
 
         self.mapView.addAnnotation(annotation) 
 

 

 
        } 
 
       } 
 
      } 
 
      self.tableView.reloadData() 
 
     }) 
 
    }

2)それから私のtableViewは正常に設定されています:posts [indexPath.row]は、それに合わせて特別に作られたクラスから引き出します。

しかし、問題に戻って、すべての場所が表示されます。地図はすべての会場で過密されています。誰でも手伝ってもらえますか?

+0

iOSのためにGeofireを調べたいと思うでしょう:https://github.com/firebase/geofire-objc –

+0

私の問題は、これを私のコードに実装する方法がわかりません。 ViewDidloadからすべてを取り出します。だから私はgeofireの呼び出しを私のプロジェクトにどのように統合できるのか分かりません。 –

答えて

1

私はIOS開発者ではないので、コードをガイドすることはできません。しかし、これを達成するには、何らかのジオロケーションクエリーを作成する必要があります。

あなたの場合、半径に基づいてデータをフィルタリングする必要があります。

これを達成するには、センター(おそらくユーザーの場所または場所の検索の結果)と各場所の中心までの距離が必要です。

あなたがこれを持っている場合は、クエリは次のようになります。

if (distance <= radius) { 
    // location is in radius 
} 

を私はちょうどので、多分これはあなたが間の距離を計算する方法がわかります(あなたを助け、このためのJavaScriptライブラリーを構築しました2箇所): https://github.com/Orlandster1998/geo-on-fire/blob/master/src/gof-utils.js#L215

か、ここのドキュメント:今 https://github.com/Orlandster1998/geo-on-fire/wiki/Basic-usage#query-by-radius

あなたは間違いなく、より多くの広告を行くべき照会する大量のデータを持っている場合いくつかの種類のジオハッシュを使用しています。

関連する問題