我目前正在开发一个项目,需要向我的Firebase数据库发送经度和纬度数据。当我在模拟器中运行程序时,它将数据发送到数据库就好了,但是当我在手机上运行数据时,它并没有将数据发送到数据库。我使用GeoFire发送此数据,这里是相关代码:
@objc func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let latestLocation: AnyObject = locations[locations.count - 1]
let geofireRef = FIRDatabase.database().reference()
let geoFire = GeoFire(firebaseRef: geofireRef)
geoFire.setLocation(CLLocation(latitude: latestLocation.coordinate.latitude, longitude: latestLocation.coordinate.longitude), forKey: "WeGotItBitchez") { (error) in
if (error != nil) {
print("An error occured: \(error)")
} else {
print("Saved location successfully!")
}
}