fix bug
This commit is contained in:
@ -46,7 +46,8 @@ export class AmapPoiPickerComponent implements OnInit {
|
||||
'AMap.PoiPicker',
|
||||
'AMap.Scale',
|
||||
'AMap.InfoWindow',
|
||||
'AMap.Geolocation'
|
||||
'AMap.Geolocation',
|
||||
'AMap.Geocoder'
|
||||
],
|
||||
AMapUI: {
|
||||
// 是否加载 AMapUI,缺省不加载
|
||||
@ -110,11 +111,18 @@ export class AmapPoiPickerComponent implements OnInit {
|
||||
|
||||
infoWindow.setContent(`地址: <pre>${poi.name}</pre>`);
|
||||
infoWindow.open(map, marker.getPosition());
|
||||
|
||||
map.setCenter(marker.getPosition());
|
||||
//获取行政区信息
|
||||
map.getCity(function (info: any) {
|
||||
poi.cityInfo = info;
|
||||
//获取地址所在的行政区
|
||||
AMap.plugin('AMap.Geocoder', () => {
|
||||
var geocoder = new AMap.Geocoder({
|
||||
city: poi.adcode
|
||||
});
|
||||
geocoder.getLocation(poi.name, (status: any, result: any) => {
|
||||
if (status === 'complete' && result.info === 'OK') {
|
||||
// result中对应详细地理坐标信息
|
||||
this.poi.cityInfo = result.geocodes[0].addressComponent;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,9 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
declare var AMap: any;
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AmapService {
|
||||
constructor() {}
|
||||
public length = 0;
|
||||
public time = 0;
|
||||
|
||||
constructor() { }
|
||||
sub = new Subject<any>();
|
||||
|
||||
//计算路径驾车最优路线的长度与所需时间
|
||||
drivingCompute(starts: any[], ends: any[]): Observable<any> {
|
||||
AMap.plugin('AMap.Driving', () => {
|
||||
let driving = new AMap.Driving({
|
||||
// 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
|
||||
policy: AMap.DrivingPolicy.LEAST_TIME
|
||||
});
|
||||
const points = starts.concat(ends).map(item => {
|
||||
return { keyword: item.address, city: item.city };
|
||||
});
|
||||
driving.search(points, (status: any, result: any) => {
|
||||
const repData = { distance: (result.routes[0].distance / 1000).toFixed(2), time: (result.routes[0].time / 60 / 60).toFixed(2) };
|
||||
this.sub.next(repData);
|
||||
});
|
||||
});
|
||||
return this.sub;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user