2017-04-27 5 views
1

マーカーが作成されると、マーカーとデータベースにすぐに表示されます。 それを削除すると、ビューを更新するまで地図に残ります。私は即座に地図でそれを削除したいが、どのように考えていない。 提案がありますか?Google Baseのマーカーがfirebaseから検索されました

これは私がまた私は、マーカー

func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D) { 
     print("You tapped at \(coordinate.latitude), \(coordinate.longitude)") 
     let alertController = UIAlertController(title: "Crea Marker", message: "...", preferredStyle: UIAlertControllerStyle.alert) //Replace UIAlertControllerStyle.Alert by UIAlertControllerStyle.alert 
     let DestructiveAction = UIAlertAction(title: "Annulla", style: UIAlertActionStyle.cancel) { 
      (result : UIAlertAction) -> Void in 
      print("Annulla") 
     } 

     // Replace UIAlertActionStyle.Default by UIAlertActionStyle.default 
     let okAction = UIAlertAction(title: "Crea", style: UIAlertActionStyle.default) { 
      (result : UIAlertAction) -> Void in 
      let ref = FIRDatabase.database().reference().child("userdata") 
      let currentUser = FIRAuth.auth()?.currentUser 
      let displayName = currentUser?.displayName 
      let post = ["username": displayName,"uid": currentUser?.uid as Any,"latitude": coordinate.latitude,"longitude": coordinate.longitude, "firstname":"test"] 
      ref.childByAutoId().setValue(post) 

      print("Entra") 
     } 

     alertController.addAction(DestructiveAction) 
     alertController.addAction(okAction) 
     self.present(alertController, animated: true, completion: nil) 
    } 

N.B.を作成するために使用する機能を入れて、私はcicle

​​

ためにfirebaseとshowマーカーからデータを取り出す方法ですイムFirebase

EDITから手動でデータを削除:あなたがもう一度firebaseデータを呼び出したりagin

それをrefresingている私のexprienceを1として This is a gif for a better explain

+0

削除マーカーのためのコードはありますか? – CodeChanger

+0

im手動でのみデータベースから削除する – GaTz

+0

Firebaseから手動で削除していますか? – CodeChanger

答えて

0

場合は、以下を使用してマップをクリアするために持っているよりもYES方法

let ref = FIRDatabase.database().reference().child("userdata") 
ref.observe(.childAdded, with: { (snapshot) in 
    ref.observe(FIRDataEventType.value, with: { (snapshot) in 
     if (snapshot.value as? [String:Any]) != nil { 

      //Here Before adding any other marker You have to clear your MAP 
      mapView.clear() 

      for rest in snapshot.children.allObjects as! [FIRDataSnapshot] { 
       guard let Dict = rest.value as? [String: AnyObject] else { 
        continue 
       } 
       let latitude = Dict["latitude"] 
       let longitude = Dict["longitude"] 
       let username = Dict["username"] 
       let model = Dict["firstname"] 
       let marker = GMSMarker() 
       marker.position = CLLocationCoordinate2D(latitude: latitude as! CLLocationDegrees, longitude: longitude as! CLLocationDegrees) 
       marker.title = username as? String 
       marker.snippet = model as? String 
       mapView.selectedMarker = marker 
       marker.map = mapView 
      } 
     } 
    }) 
}) 

これは、MAP

0123であり、古いマーカーを使用して問題を解決します

ただし、データを更新していない場合は、このマーカーを更新または削除するこのmapView.clear()メソッドを使用してください。参照のためのリンクの下の

チェック:

https://developers.google.com/maps/documentation/ios-sdk/marker

+0

回答ありがとうございますが、データベースからデータを削除した場合、マーカーはその位置にとどまりますので同じです – GaTz

+0

[mapView clear]メソッドを呼び出しましたか? – CodeChanger

+0

はい、誰かが「チート」について話します:辞書にマーカーを追加し、値をデータベースと比較します。 Javaの人々でハッシュマップを使用しますが、私はすぐにどのようにわかりません – GaTz

関連する問題