Angular google Map不会渲染并且不会抛出任何错误

时间:2015-06-18 16:36:15

标签: javascript angularjs google-maps maps

我是棱角分明的新人,但我认为我有一切正确。这是一个非常简单的设置。

这是应用

var appLocations = angular.module('locations', ['uiGmapgoogle-maps']).config(function(uiGmapGoogleMapApiProvider) {

    uiGmapGoogleMapApiProvider.configure({
        // key: 'I am not providing a key',
        v: '3.17',
        libraries: 'weather,geometry,visualization'
    });
});

appLocations.controller('LocationsController', function($scope, $http) {
    $http.get('/json/locations/')
        .then(function(res){
            $scope.locations = res.data;
        });
});

appLocations.controller('MapController', function($scope, $http) {
    $http.get('/json/locations/')
        .then(function(res){
            $scope.locations = res.data;
        });
    $scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 };
});

这是标记

<div class="main1-in" ng-app="locations">
        <div ng-controller="MapController">
            <ui-gmap-google-map></ui-gmap-google-map>
        </div>
        <div class="health-care large-12 medium-11 small-12">
            <h1>Welcome</h1>
            <?php dynamic_sidebar('Welcome')?>
        </div>
        <div class="location large-12 medium-12 small-12" ng-controller="LocationsController">
            <h2>LOCATIONS</h2>
            <div class="search">
                <input type="text" class="text-field" value="Find a location" ng-model="search" placeholder="Search...">
                <span><i class="fa fa-search"></i></span>
                <div class="clear"></div>
            </div>
            <div class="clear"></div>
            <div class="location-carousel large-12 medium-12 small-12">
                <ul>
                    <li ng-repeat="location in locations | filter:search">
                        <div class="location-in"  itemscope itemtype="http://schema.org/MedicalClinic">
                            <img src="{{location.thumbnail[0]}}" alt="img" width="273" height="157">
                            <h6><span itemprop="name">{{location.Name}}</span></h6>
                            <p itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
                                <span itemprop="streetAddress">{{location.address1}} {{location.address2}}</span><br>
                                <span itemprop="addressLocality">{{location.city}}</span>,
                                <span itemprop="addressRegion">{{location.state}}</span>
                                <span itemprop="postalCode">{{location.zip}}</span>
                            </p>
                            <small itemprop="telephone">{{location.phoneNumber}}</small>
                            <a href="{{location.permalink}}" itemprop="url">Visit location page</a>
                        </div>
                    </li>
                </ul>
            </div>

        </div>
    </div>

我在控制台中没有错误。应用程序的其余部分呈现但地图本身不呈现。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

根据文档,您的所有操作都是正确的,除了一件事,您需要提及地图中心和地图的缩放级别,请参阅快速入门文档

<ui-gmap-google-map center='map.center' zoom='map.zoom'></ui-gmap-google-map>

map.centermap.zoom从您提供的MapController中获取,本地副本适合我。检查您是否对代码的其他部分有任何问题。

当然,

.angular-google-map-container { height: 400px; }

进入CSS,或动态设置访问DOM的高度。

相关问题