### File

`src/app/_services/location.service.ts`

### Index

###### Properties
areaNames Private areaNamesList areaNamesSubject areaTypes Private areaTypesList areaTypesSubject
###### Methods
getAreaNameByLocation getAreaNames getAreaTypeByArea getAreaTypes

### Constructor

`constructor(httpClient: HttpClient)`
Defined in src/app/_services/location.service.ts:17
Parameters :
Name | Type | Optional
httpClient | `HttpClient` | No

### Methods

getAreaNameByLocation
`getAreaNameByLocation(location: string, areaNames: object)`
Defined in src/app/_services/location.service.ts:28
Parameters :
Name | Type | Optional
location | `string` | No
areaNames | `object` | No
Returns : `string`

getAreaNames
`getAreaNames()`
Defined in src/app/_services/location.service.ts:21
Returns : `void`

getAreaTypeByArea
`getAreaTypeByArea(area: string, areaTypes: object)`
Defined in src/app/_services/location.service.ts:47
Parameters :
Name | Type | Optional
area | `string` | No
areaTypes | `object` | No
Returns : `string`

getAreaTypes
`getAreaTypes()`
Defined in src/app/_services/location.service.ts:40
Returns : `void`

### Properties

areaNames
Type : `object`
Default value : `{}`
Defined in src/app/_services/location.service.ts:11

Private areaNamesList
Type : `BehaviorSubject<object>`
Default value : `new BehaviorSubject<object>(this.areaNames)`
Defined in src/app/_services/location.service.ts:12

areaNamesSubject
Type : `Observable<object>`
Default value : `this.areaNamesList.asObservable()`
Defined in src/app/_services/location.service.ts:13

areaTypes
Type : `object`
Default value : `{}`
Defined in src/app/_services/location.service.ts:15

Private areaTypesList
Type : `BehaviorSubject<object>`
Default value : `new BehaviorSubject<object>(this.areaTypes)`
Defined in src/app/_services/location.service.ts:16

areaTypesSubject
Type : `Observable<object>`
Default value : `this.areaTypesList.asObservable()`
Defined in src/app/_services/location.service.ts:17

    import { Injectable } from '@angular/core';
    import { BehaviorSubject, Observable } from 'rxjs';
    import { environment } from '@src/environments/environment';
    import { first } from 'rxjs/operators';
    import { HttpClient } from '@angular/common/http';

    @Injectable({
      providedIn: 'root',
    })
    export class LocationService {
      areaNames: object = {};
      private areaNamesList: BehaviorSubject<object> = new BehaviorSubject<object>(this.areaNames);
      areaNamesSubject: Observable<object> = this.areaNamesList.asObservable();

      areaTypes: object = {};
      private areaTypesList: BehaviorSubject<object> = new BehaviorSubject<object>(this.areaTypes);
      areaTypesSubject: Observable<object> = this.areaTypesList.asObservable();

      constructor(private httpClient: HttpClient) {}

      getAreaNames(): void {
        this.httpClient
          .get(`${environment.cicMetaUrl}/areanames`)
          .pipe(first())
          .subscribe((res: object) => this.areaNamesList.next(res));
      }

      getAreaNameByLocation(location: string, areaNames: object): string {
        const keywords = location.toLowerCase().split(' ');
        for (const keyword of keywords) {
          const queriedAreaName: string = Object.keys(areaNames).find((key) =>
            areaNames[key].includes(keyword)
          );
          if (queriedAreaName) {
            return queriedAreaName;
          }
        }
      }

      getAreaTypes(): void {
        this.httpClient
          .get(`${environment.cicMetaUrl}/areatypes`)
          .pipe(first())
          .subscribe((res: object) => this.areaTypesList.next(res));
      }

      getAreaTypeByArea(area: string, areaTypes: object): string {
        const keywords = area.toLowerCase().split(' ');
        for (const keyword of keywords) {
          const queriedAreaType: string = Object.keys(areaTypes).find((key) =>
            areaTypes[key].includes(keyword)
          );
          if (queriedAreaType) {
            return queriedAreaType;
          }
        }
      }
    }

# result-matching ""

# No results matching ""