Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. var locationRefrence: StorageReference {
  2. return Storage.storage().reference().child("Locations")
  3. }
  4.  
  5. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  6.  
  7. guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
  8. print("locations = (locValue.latitude) (locValue.longitude)")
  9.  
  10. if mapViewObj == nil {
  11. mapViewObj = GMSMapView()
  12.  
  13. let camera = GMSCameraPosition.camera(withLatitude: locValue.latitude, longitude: locValue.longitude, zoom: 16.0)
  14. mapViewObj = GMSMapView.map(withFrame: self.mapView.frame, camera: camera)
  15. mapViewObj.delegate = self
  16. mapViewObj.isMyLocationEnabled = true
  17. mapViewObj.settings.myLocationButton = true
  18.  
  19. self.mapView.addSubview(mapViewObj)
  20. }
  21.  
  22. let location = "(locValue.latitude) (locValue.longitude)"
  23.  
  24. firebaseUpload(location: location)
  25. }
  26.  
  27. func firebaseUpload(location: String) {
  28.  
  29. let uploadLocationRef = locationRefrence.child("location")
  30.  
  31. let locationData = location.data(using: .utf8)
  32.  
  33. let uploadTask = uploadLocationRef.putData(locationData!, metadata: nil) { (metadata, error) in
  34. print(metadata ?? "No metadata")
  35. print(error ?? "No error")
  36. }
  37.  
  38. uploadTask.observe(.progress) { (snapshot) in
  39. print(snapshot.progress ?? "No progress")
  40. }
  41.  
  42. uploadTask.resume()
  43. }
  44.  
  45. func fetchLocationFromFirebase() {
  46. let downloadLocationRef = locationRefrence.child("location")
  47.  
  48. let downloadTask = downloadLocationRef.getData(maxSize: 1024 * 1024 * 12) { (data, error) in
  49. if let data = data {
  50. let locationStr = String(data: data, encoding: .utf8)
  51. print("Fetched Locations : (locationStr ?? "Nothing fetched...")")
  52. }
  53. print(error ?? "No error")
  54. }
  55.  
  56. downloadTask.observe(.progress) { (snapshot) in
  57. print(snapshot.progress ?? "No progress")
  58. }
  59.  
  60. downloadTask.resume()
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement