未捕获的RangeError:最大调用堆栈大小超过了log

时间:2015-06-25 19:24:41

标签: html angularjs google-maps cordova ionic-framework

在Google地图上绘制多个标记时,我在Ionic框架的日志中收到未捕获的RangeError:超出最大调用堆栈大小错误消息。

我正在使用Cordova Google插件来制作地图。任何人都可以找出错误在我的代码中的位置吗?

var autocompleteFrom = new google.maps.places.Autocomplete(inputFrom, options);
var autocompleteto = new google.maps.places.Autocomplete(inputto,options);

google.maps.event.addListener(autocompleteFrom, 'place_changed', function() {
    var bounds = new google.maps.LatLngBounds();
    var place = autocompleteFrom.getPlace();
    $rootScope.fromLat = place.geometry.location.lat();
    $rootScope.fromLng = place.geometry.location.lng();
    $rootScope.from = place.formatted_address;
    $scope.placesfrom = $rootScope.from;
    fromlat = $rootScope.fromLat;
    fromlng = $rootScope.fromLng;
    var Mapoptions ={
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl:false,
        zoomControl:false,
        draggable:true,
        mapTypeControl:false,
        scaleControl:false,
        streetViewControl:false,
        overviewMapControl:false,
        rotateControl:true
    }
    var googlemaphome = document.getElementById('googlemap-home');
    var Map = new google.maps.Map(googlemaphome,Mapoptions);
    var marker;
    var markers = [
            [fromlat,fromlng],
            [28.6328,77.2197]
    ];

    for(var i = 0; i < markers.length; i++ ) {
        var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
        bounds.extend(position);
        marker = new google.maps.Marker({
            position: position,
            icon: 'img/marker.png',
            map: Map
        });
    }
    Map.fitBounds(bounds);
    var boundsListener = google.maps.event.addListener((Map), 'bounds_changed', function(event) {
        this.setZoom(14);
        google.maps.event.removeListener(boundsListener);
    });
    $scope.$apply();
});

`

1 个答案:

答案 0 :(得分:1)

我认为问题在于:

  

var position = new google.maps.LatLng(markers [i] [1],markers [i] [2]);

由于markers[]数组中的子数组只有2个元素,而数组的索引从0开始,我相信你应该将这一行改为

  

var position = new google.maps.LatLng(markers [i] [ 0 ],marker [i] [ 1 ]); //使用0和1而不是1和2