/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ // Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1265 /// import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import * as i0 from "@angular/core"; /** * Angular service that wraps the Google Maps Geocoder from the Google Maps JavaScript API. * See developers.google.com/maps/documentation/javascript/reference/geocoder#Geocoder */ export class MapGeocoder { constructor(_ngZone) { this._ngZone = _ngZone; } /** * See developers.google.com/maps/documentation/javascript/reference/geocoder#Geocoder.geocode */ geocode(request) { return new Observable(observer => { this._getGeocoder().then(geocoder => { geocoder.geocode(request, (results, status) => { this._ngZone.run(() => { observer.next({ results: results || [], status }); observer.complete(); }); }); }); }); } _getGeocoder() { if (!this._geocoder) { if (google.maps.Geocoder) { this._geocoder = new google.maps.Geocoder(); } else { return google.maps.importLibrary('geocoding').then(lib => { this._geocoder = new lib.Geocoder(); return this._geocoder; }); } } return Promise.resolve(this._geocoder); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.0-next.2", ngImport: i0, type: MapGeocoder, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.0-next.2", ngImport: i0, type: MapGeocoder, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0-next.2", ngImport: i0, type: MapGeocoder, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i0.NgZone }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFwLWdlb2NvZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2dvb2dsZS1tYXBzL21hcC1nZW9jb2Rlci9tYXAtZ2VvY29kZXI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