0

I am trying to find a way to use multiple markers on an OSM map. In spite of a frightening number of tutorials, I am unable find a solution to recover the info (longitude, latitude of locations) in firebase DB to make markers.

import * as L from 'leaflet';
import { ActivatedRoute } from '@angular/router';
import { LieuService, Lieu } from 'src/app/services/lieu.service';
import { AdresseService, Adresse } from 'src/app/services/adresse.service';
import { NavController, LoadingController } from '@ionic/angular';


@Component({
selector: 'app-carte',
templateUrl: './carte.page.html',
styleUrls: ['./carte.page.scss'],
})
export class CartePage implements OnInit {

name = 'Angular';
map: any;
myIcon: any;
resadd = [];

adresse: Adresse = {
  ville: '',
  cp: 0,
  latitude: 0,
  longitude: 0,
  numero: 0,
  rue: ''
};

lieu: Lieu = {
  adresse: this.adresse,
  nom: '',
  img: '',
  capacite: 0,
  jours_ouverts: []
};

public location: any = {
  Lat: 46.325666,
  Lon: -0.467819,
};

public locationMarker: any = {
  Lat: this.adresse.latitude,
  Lon: this.adresse.longitude,
  label: this.lieu.nom
};

constructor(private lieuService: LieuService,
            private adresseService: AdresseService) { }

ngOnInit() {
  this.initMap();
  // this.addMarker();
  console.log(this.adresse.latitude, this.adresse.longitude);
}

public initMap(): void {
  document.getElementById('map');
  const map = L.map('map', {
    center: [this.location.Lat, this.location.Lon],
    zoom: 13
  });

  const myIcon = L.icon({
    iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/images/marker-icon.png',
    iconSize: [25, 41],
    iconAnchor: [0, 40],
    popupAnchor: [-35, -39]
  });

  L.control.scale().addTo(map);

  L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
  }).addTo(map);


  }
  // leafletMap() {
  //   for (const adresseService of this.resadd) {
  //     L.marker([this.resadd.longitude, resadd.latitude]).addTo(this.map)
  //       .bindPopup(this.adresse.id)
  //       .openPopup();

//   async addMarker() {
//       this.adresseService.getAdresse(this.adresse.id).subscribe(resadd => {
//         this.lieu.adresse = resadd;
//         console.log(this.lieu);
//         L.marker([resadd.longitude, resadd.latitude], {icon: this.myIcon})
//         .addTo(this.map)
//         .bindPopup(this.locationMarker.label)
//         .openPopup();
//       });
//  }
    //     L.marker([this.adresseService.getAdresse, this.locationMarker.Lat], {icon: this.myIcon})
    //     .addTo(this.map)
    //     .bindPopup(this.locationMarker.label)
    //     .openPopup();
    //   });
    // }); 

In comments are the solutions I've tried that I think are not correct in my opinion.

5
  • Is your adresseService.getAddresse function call returning anything? Are there any errors in the console? Are you able to add a static marker to your map?
    – pk.
    Commented Feb 11, 2020 at 15:08
  • @pk adresseService.getAddresse is supposed to get the id, with its I am supposed to get the longitude and latitude of the place linked to this address.
    – NCA.Rony
    Commented Feb 12, 2020 at 11:57
  • I've got the error " error "Function CollectionReference.doc()" ". and at the moment I'm trying to retrieve via a Json file the data for the markers.
    – NCA.Rony
    Commented Feb 12, 2020 at 12:05
  • A quick google tells me that your error is related to firebase. It doesn't look like id is set on your adresse variable.
    – pk.
    Commented Feb 13, 2020 at 13:40
  • @pk. you probably right, but it's still not realy the goodway to do what i want :/. (Don't worry, I'm keeping your solution aside. The client provided us with a very illogical BBD.)
    – NCA.Rony
    Commented Feb 14, 2020 at 8:39

0