author Damien Dell'Amico <damien.dellamico@gmail.com>
 *  copyright license import { Component , ViewChild , ElementRef , NgZone } from '@angular/core' ; import { ViewController , AlertController } from 'ionic-angular' ; import { MapService } from '../../providers/map/map.service' ; import { BasePage } from '../base-page' ; @ Component ( { templateUrl : 'search.tpl.html' } ) export class SearchPage extends BasePage { @ ViewChild ( 'searchbar' , { read : ElementRef } ) searchbar : ElementRef ; private nearbyPlaces : Array < any > = [ ] ; private addressElement : HTMLInputElement = null ; constructor ( private mapService , private zone , protected alertCtrl , private viewCtrl ) { super ( alertCtrl ) ; } ionViewDidLoad ( ) { this . initAutocomplete ( ) ; this . loadNearbyPlaces ( ) ; } dismiss ( location ? ) { if ( location ) { this . mapService . mapCenter = location ; } if ( this . addressElement ) { this . addressElement . value = '' ; } this . viewCtrl . dismiss ( ) ; } /***
     * Place item has been selected
     */ selectPlace ( place ) { this . dismiss ( place . geometry . location ) ; } private initAutocomplete ( ) { this . addressElement = this . searchbar . nativeElement . querySelector ( '.searchbar-input' ) ; this . mapService . createAutocomplete ( this . addressElement ) . subscribe ( ( location ) => { this . dismiss ( location ) ; } , ( error ) => { this . displayErrorAlert ( ) ; console . error ( error ) ; } ) ; } private loadNearbyPlaces ( ) { this . nearbyPlaces = [ ] ; this . mapService . loadNearbyPlaces ( ) . subscribe ( ( _nearbyPlaces ) => { this . zone . run ( ( ) => { this . nearbyPlaces . push . apply ( this . nearbyPlaces , _nearbyPlaces ) ; } ) ; } , ( error ) => { this . displayErrorAlert ( ) ; console . error ( error ) ; } ) ; } }