Guest User

Untitled

a guest
Mar 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. ionViewDidLoad() {
  2. console.log('ionViewDidLoad LocationsPage');
  3. this.getUserLocation();
  4. this.subscription = this.locationService.hits
  5. .subscribe((hits) =>{
  6. this.markers = hits;
  7. this.filterLocations(this.locationCategory, this.markers)
  8.  
  9. },
  10. (err)=> {
  11. console.log(err);
  12. });
  13. }
  14.  
  15. private getUserLocation() {
  16. if (navigator.geolocation) {
  17. navigator.geolocation.getCurrentPosition(position => {
  18. this.userLat = position.coords.latitude;
  19. this.userLong = position.coords.longitude;
  20.  
  21. this.locationService.getLocations(this.radius, [this.userLat, this.userLong]);
  22. console.log(this.locationService.hits);
  23. });
  24. }
  25. }
  26. filterLocations(category: string, markers) {
  27. console.log(markers);
  28. this.filteredMarkers = markers;
  29. console.log('markers to be filtered: ', this.filteredMarkers, 'category: ',category);
  30. if (category != ''){
  31. category = category.toLocaleLowerCase();
  32. this.filteredMarkers = this.filteredMarkers.filter(location => {
  33. console.log(this.filteredMarkers);
  34. return !category || location.category.toLowerCase().indexOf(category) !== -1;
  35. });
  36. }
  37. return this.filteredMarkers;
  38. }
  39.  
  40. getLocations(radius: number, coords: Array<number>) {
  41. let newName = '';
  42. let newDescription = '';
  43.  
  44. this.geoFire.query({
  45. center: coords,
  46. radius: radius
  47. })
  48. .on('key_entered', (key, location, distance) => {
  49.  
  50.  
  51. console.log(newName);
  52. let hit = {
  53. location: location,
  54. distance: distance,
  55. name: '',
  56. description: '',
  57. category: ''
  58. };
  59. let currentHits = this.hits.value;
  60.  
  61.  
  62. this.getLocationData(key).subscribe(
  63. (location) =>{
  64. newName = location.name;
  65. hit.name = location.name;
  66. hit.description = location.description;
  67. hit.category = location.category;
  68. currentHits.push(hit);
  69. this.hits.next(currentHits);
  70.  
  71. }
  72. );
  73.  
  74. });
  75. }
  76.  
  77. getLocationData(ID: string): Observable<Location>{
  78. return this.db.object('/locationData/'+ID).valueChanges();
  79. }
Add Comment
Please, Sign In to add comment