0
votes

l am trying to get objects keys from JSON API url , content on latitude and longitude from server . The data json api content on Object keys and those keys are change all time . l want to get only the coordinates inside of those Object keys and add it to leaflet map marker as array then show on map .

  protected points: { lng: number, lat: number }[] = [];
  Data : any

  data(){

    this.http.get("xxxxxxxxxxxx",{},{}).
    then((data) => {
      this.Data = JSON.parse(data.data);
      this.points = Object.keys(this.Data)
        .map(key => this.Data[key])
        .map((position) => ({
          lat: position[0],
          lon: position[1]
        }));
      this.points.forEach((point) => {

          new L.Marker([point]

Live code

1

1 Answers

0
votes

new L.Marker([point]

Should have been:

new L.Marker(point (no need for square brackets)

Your point variable is already a LatLngExpression (in your case: an object with lat and lon properties)