import { LoginPlace } from './../interfaces/user-connections.interface';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class GeolocationService {

  constructor(
    private http: HttpClient
  ) { }

  getLocationName(location: LoginPlace){
    return this.getQuery(`latitude=${location.latitude}&longitude=${location.longitude}&localityLanguage=es`).pipe(map((data: any) => data))
  }

  getQuery(query: string){
    const URL = `https://api.bigdatacloud.net/data/reverse-geocode-client?${query}`;
    return this.http.get(URL);
  }
}
