import { Component , ViewChild , ElementRef } from '@angular/core' ; import { IonicPage , NavController , NavParams } from 'ionic-angular' ; import { GeolocationProvider } from '../../providers/geolocation/geolocation' ; declare var BMap ; declare var BMap_Symbol_SHAPE_POINT ; @ IonicPage ( ) @ Component ( { selector : 'page-baidu-map' , templateUrl : 'baidu-map.html' , } ) export class BaiduMapPage { @ ViewChild ( 'map' ) map_container : ElementRef ; map : any ; marker : any ; geolocation1 : any ; myIcon : any ; constructor ( public navCtrl , public html5Geolocation , public navParams ) { this . html5Geolocation . watchPosition ( ) ; this . myIcon = new BMap . Icon ( "assets/icon/favicon.ico" , new BMap . Size ( 30 , 30 ) ) ; } ionViewDidLoad ( ) { console . log ( 'ionViewDidLoad BaiduMapPage' ) ; } ionViewDidEnter ( ) { let map = this . map = new BMap . Map ( this . map_container . nativeElement , { enableMapClick : true , enableScrollWheelZoom : true , enableContinuousZoom : true } ) ; let point = new BMap . Point ( 113.38028471135 , 23.129702256122 ) ; let marker = new BMap . Marker ( point ) ; this . map . addOverlay ( marker ) ; map . centerAndZoom ( point , 18 ) ; } getLocationByBrowser ( ) { let geolocation1 = this . geolocation1 = new BMap . Geolocation ( ) ; geolocation1 . getCurrentPosition ( ( r ) => { let mk = this . marker = new BMap . Marker ( r . point , { icon : this . myIcon } ) ; console . log ( '打印：' , geolocation1 . getStatus ( ) ) ; if ( geolocation1 . getStatus ( ) == 'BMAP_STATUS_SUCCESS' ) { this . map . addOverlay ( mk ) ; this . map . panTo ( r . point , 16 ) ; console . log ( '浏览器定位：您的位置是 ' + r . point . lng + ',' + r . point . lat ) ; } else { alert ( 'failed' + this . geolocation1 . getStatus ( ) ) ; } } , { enableHighAccuracy : false } ) ; } getLocationByIp ( ) { let myCity = new BMap . LocalCity ( ) ; myCity . get ( result => { let cityName = result . name ; this . map . setCenter ( cityName ) ; console . log ( "当前定位城市:" + cityName ) ; } ) ; } getLocationByCity ( ) { let city = "郑州" ; if ( city != "" ) { this . map . centerAndZoom ( city , 16 ) ; } } getLocationByLatLon ( ) { let aa = this . html5Geolocation . latitude ; let bb = this . html5Geolocation . longitude ; let point = new BMap . Point ( bb , aa ) ; let marker = this . marker = new BMap . Marker ( point , { icon : this . myIcon } ) ; this . map . addOverlay ( marker ) ; this . map . centerAndZoom ( point , 16 ) ; } getLocation ( ) { } }