Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var locationRefrence: StorageReference {
- return Storage.storage().reference().child("Locations")
- }
- func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
- guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
- print("locations = (locValue.latitude) (locValue.longitude)")
- if mapViewObj == nil {
- mapViewObj = GMSMapView()
- let camera = GMSCameraPosition.camera(withLatitude: locValue.latitude, longitude: locValue.longitude, zoom: 16.0)
- mapViewObj = GMSMapView.map(withFrame: self.mapView.frame, camera: camera)
- mapViewObj.delegate = self
- mapViewObj.isMyLocationEnabled = true
- mapViewObj.settings.myLocationButton = true
- self.mapView.addSubview(mapViewObj)
- }
- let location = "(locValue.latitude) (locValue.longitude)"
- firebaseUpload(location: location)
- }
- func firebaseUpload(location: String) {
- let uploadLocationRef = locationRefrence.child("location")
- let locationData = location.data(using: .utf8)
- let uploadTask = uploadLocationRef.putData(locationData!, metadata: nil) { (metadata, error) in
- print(metadata ?? "No metadata")
- print(error ?? "No error")
- }
- uploadTask.observe(.progress) { (snapshot) in
- print(snapshot.progress ?? "No progress")
- }
- uploadTask.resume()
- }
- func fetchLocationFromFirebase() {
- let downloadLocationRef = locationRefrence.child("location")
- let downloadTask = downloadLocationRef.getData(maxSize: 1024 * 1024 * 12) { (data, error) in
- if let data = data {
- let locationStr = String(data: data, encoding: .utf8)
- print("Fetched Locations : (locationStr ?? "Nothing fetched...")")
- }
- print(error ?? "No error")
- }
- downloadTask.observe(.progress) { (snapshot) in
- print(snapshot.progress ?? "No progress")
- }
- downloadTask.resume()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement