我在使用地图路线服务时遇到此错误的帮助,我正在关注使用ng-2和SebastianM / angular2-实施Google地图路线服务的问题Directions service #495谷歌地图,我不确定我是否遗漏了一些东西,我已经对此进行了真正的研究,并且需要有关错误来源的帮助。
EXCEPTION: Uncaught (in promise): RangeError: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
这是方向服务组件/指令,我已经在我的module.ts中声明了
import { Component, OnInit, Input } from '@angular/core';
import { MapsAPILoader, SebmGoogleMap, GoogleMapsAPIWrapper} from 'angular2-google-maps/core';
import { Session } from '../../../session';
declare var google: any;
@Component({
selector: 'sebm-google-map-directions',
templateUrl: 'app/modules/move_requests/components/sebm-google-directions.component.html',
styleUrls: [
'app/modules/move_requests/components/move_requests.component.css'
]
})
export class DirectionsMapDirective implements OnInit {
@Input() origin: any;
@Input() destination: any;
constructor(private mapsAPI: MapsAPILoader,private mapsAPIWrapper: GoogleMapsAPIWrapper) {}
ngOnInit(): void {
let latlngOrigin = Session.get('location_coordinates');
let latlngDest = Session.get('to_location_coords');
this.mapsAPIWrapper.getNativeMap().then(map =>{
this.origin = new google.maps.LatLng(latlngOrigin.lat,latlngOrigin.lng);
this.destination = new google.maps.LatLng(latlngDest.lat,latlngDest.lng);
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
directionsDisplay.setMap(map);
directionsService.route({
origin: this.origin,
destination: this.destination,
waypoints: [],
optimizeWaypoints: true,
travelMode: 'DRIVING',
},function (res: any, status: any){
if( status === 'OK') {
console.log("STATUS WAS OK");
directionsDisplay.setDirections(res)
} else {
window.alert('Directions request failed due to ' + status);
}
});
});
}
并在模板中有这个
<sebm-google-map style="height: 300px;">
<sebm-google-map-directions [origin]="origin" [destination]="destination"></sebm-google-map-directions>
</sebm-google-map>
任何可能导致我解决错误的帮助或建议都将不胜感激,谢谢。
答案 0 :(得分:0)
我的错是我没有指示服务作为指令,但是一个组件,我已经将指示服务移动到指令,并在我的模块中声明它然后将其用作html标签在主机组件中,如果有人想看到代码,只需评论这个问题的主题。