将位置信息保存到数据库中的唯一用户ID?

时间:2017-04-11 16:48:36

标签: firebase firebase-realtime-database annotations location

在我的应用程序中,用户有一个选项,可以在按下按钮时保存他们的位置。在他们的位置的lat和lng保存到我的数据库时,它不会保存在我的Database中显示的唯一ID下。

我不确定我需要添加或更改这些"个人位置"在他们自己的个人用户标识下保存为分支。这样我就可以在以后将他们保存的位置加载到特定用户。

我很感激所有的帮助,因为我真的被卡住了!以下是我的相关问题代码。谢谢!

 //User can save their location
@IBAction func findUserLocationAndDropPin(_ sender: UIButton) {

    let userLocationCoordinates = CLLocationCoordinate2DMake((locationManager.location?.coordinate.latitude)!, (locationManager.location?.coordinate.longitude)!)

    let pinForUserLocation = MGLPointAnnotation()

    pinForUserLocation.coordinate = userLocationCoordinates

    pinForUserLocation.title = ""
    pinForUserLocation.subtitle = ""

    mapView.addAnnotation(pinForUserLocation)
    mapView.showAnnotations([pinForUserLocation], animated: true)

    //When the user clicks the button, send the CLLocation Coordinate 2D make to firebase against their user ID

    let uid = FIRAuth.auth()!.currentUser!.uid

    let locationsRef = FIRDatabase.database().reference().child("users").child("personalLocations").child(uid).childByAutoId()

    locationsRef.setValue(["lat": locationManager.location?.coordinate.latitude, "lng": locationManager.location?.coordinate.longitude])

}

0 个答案:

没有答案
相关问题