谷歌地图无法加载angularjs

时间:2013-11-02 18:19:00

标签: google-maps angularjs

您好,我一直在尝试在用户点击链接时将Google地图加载到页面上。我一直试图关注Using google maps with angularjs and angular ui,但地图没有出现。在localhost上,我得到的错误是:没有模块:地图测试。这里没有模块意味着什么?我一直遇到这样的错误。由于某种原因,它适用于JSfiddle ...... The working example

Html文件:

  <div ng-app='maptesting'>
    <div ng-controller="MapCtrl">
        <div id="map_canvas" ui-map="myMap" 
        style="height:300px;width:400px;border:2px solid #777777;margin:3px; border:1px solid" 
        ui-options="mapOptions" 
        ui-event="{'map-idle' : 'onMapIdle()'}"
        >
        </div>

        <!--In addition to creating the markers on the map, div elements with existing google.maps.Marker object should be created to hook up with events -->
        <div ng-repeat="marker in myMarkers" ui-map-marker="myMarkers[$index]"
                        ui-event="{'map-click': 'markerClicked(marker)'}">
        </div>
    </div>
</div>

javascript文件:

//Add the requried module 'angular-ui' as a dependency
angular.module('maptesting', ['ui.map','ui.event']);

function MapCtrl($scope) {
    var ll = new google.maps.LatLng(13.0810, 80.2740);
    $scope.mapOptions = {
        center: ll,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    //Markers should be added after map is loaded
    $scope.onMapIdle = function() {
        if ($scope.myMarkers === undefined){    
            var marker = new google.maps.Marker({
                map: $scope.myMap,
                position: ll
            });
            $scope.myMarkers = [marker, ];
        }
    };

    $scope.markerClicked = function(m) {
        window.alert("clicked");
    };

}

实例: 关于plunker:here
关于JSfiddle:here

另外请注意,使用angularui从头开始或使用google maps with angular编写google maps和angularjs集成会更好吗? anuglarui看起来很棒但是当我尝试它时它也没有用。我在一个谷歌圈子中读到它没有更新一段时间,这可能是它不能正常运作的原因。

答案: 是的,我所缺少的是脚本标签。即:

 <script src="http://www.flocations.com/static/vendor/angular-ui/event/event.js"></script>
    <script src="http://www.flocations.com/static/vendor/angular-ui/map/ui-map.min.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 

1 个答案:

答案 0 :(得分:0)

Your Plunk没有<script></script>ui.map的{​​{1}}个元素。例如,您可能希望将这些内容包含在ui.event

<head>