1

我使用angular-google-maps模块实现了一个非常基本的地图。在页面处理完所有脚本后,我总是会在 Chrome 开发者工具控制台中发现“TypeError: undefined is not a function”,尽管一切似乎都按预期工作。

它在promise 函数$scope.control.getGMap().fitBounds($scope.bounds);中被调用时发生。uiGmapIsReady

angular.module('app', ['uiGmapgoogle-maps'])


.config(function (uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
        //    key: 'your api key',
        v: 3.17,
        libraries: 'weather,geometry,visualization'
    });
})

.controller('MainController', ['$scope', '$timeout', 'uiGmapGoogleMapApi', 'uiGmapIsReady', function ($scope, $timeout, uiGmapGoogleMapApi, uiGmapIsReady) {

    $scope.markers = [
        { latitude: 33.970675, longitude: -118.454618},
        { latitude: 33.980675, longitude: -118.454618},
        { latitude: 33.974246, longitude: -118.455458}
    ]

    uiGmapGoogleMapApi.then(function (maps) {
        $scope.bounds = new maps.LatLngBounds();
        angular.forEach($scope.markers, function (value, key) {
            var myLatLng = new maps.LatLng($scope.markers[key].latitude, $scope.markers[key].longitude);
            $scope.bounds.extend(myLatLng);
        });
        $scope.map = { center: { latitude: $scope.bounds.getCenter().lat(), longitude: $scope.bounds.getCenter().lng() }, zoom: 5 };
        $scope.map.options = { MapTypeId: maps.MapTypeId.HYBRID };

    });

    $scope.control = {};

    uiGmapIsReady.promise().then((function (maps) {
        $scope.control.getGMap().fitBounds($scope.bounds);
    }));

    $scope.refreshMap = function () {
        $scope.control.refresh({ latitude: $scope.bounds.getCenter().lat(), longitude: $scope.bounds.getCenter().lng() });
    }

    $scope.streetZoom = function () {
        $scope.control.getGMap().setZoom(14);
    }
}])

这是标记

    <ui-gmap-google-map 
        center="map.center" 
        zoom="map.zoom" 
        options="map.options"
        control="control">
        <ui-gmap-marker idkey="$index" coords="item" ng-repeat="item in markers track by $index">
            <ui-gmap-window options="windowOptions" closeclick="closeClick()">
                <p class="google-window">{{item.latitude}}, {{item.longitude}}</p>
            </ui-gmap-window>
        </ui-gmap-marker>
    </ui-gmap-google-map>

这是错误消息:

TypeError: undefined is not a function             angular.js:11655 

任何关于为什么会发生这种情况的见解将不胜感激!我觉得我打破了一些东西,不知道为什么。

4

0 回答 0